<commit_before>/*******************************************************************************
 * This file is part of TERMINAL RECALL
 * Copyright (c) 2012-2016 <NAME>
 * Part of the jTRFP.org project
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Public License v3.0
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/gpl.html
 * 
 * Contributors:
 *     chuck - initial API and implementation
 ******************************************************************************/
package org.jtrfp.trcl.obj;

import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.concurrent.Callable;
import java.util.concurrent.locks.ReentrantLock;

import org.apache.commons.math3.exception.MathArithmeticException;
import org.apache.commons.math3.geometry.euclidean.threed.Vector3D;
import org.jtrfp.trcl.MatrixWindow;
import org.jtrfp.trcl.ObjectDefinitionWindow;
import org.jtrfp.trcl.PrimitiveList;
import org.jtrfp.trcl.SpacePartitioningGrid;
import org.jtrfp.trcl.Submitter;
import org.jtrfp.trcl.WeakPropertyChangeSupport;
import org.jtrfp.trcl.beh.Behavior;
import org.jtrfp.trcl.beh.BehaviorNotFoundException;
import org.jtrfp.trcl.beh.CollisionBehavior;
import org.jtrfp.trcl.coll.CollectionActionDispatcher;
import org.jtrfp.trcl.coll.PropertyListenable;
import org.jtrfp.trcl.core.Features;
import org.jtrfp.trcl.core.NotReadyException;
import org.jtrfp.trcl.core.TRFactory;
import org.jtrfp.trcl.core.TRFactory.TR;
import org.jtrfp.trcl.core.TRFuture;
import org.jtrfp.trcl.core.TRFutureTask;
import org.jtrfp.trcl.ext.tr.GPUFactory.GPUFeature;
import org.jtrfp.trcl.game.RedFlashFactory.RedFlash;
import org.jtrfp.trcl.gpu.GL33Model;
import org.jtrfp.trcl.gpu.GPU;
import org.jtrfp.trcl.gpu.RenderList;
import org.jtrfp.trcl.gpu.Renderer;
import org.jtrfp.trcl.math.Mat4x4;
import org.jtrfp.trcl.math.Vect3D;
import org.jtrfp.trcl.math.Vect3D.ZeroNormException;
import org.jtrfp.trcl.mem.VEC4Address;

public class WorldObject implements PositionedRenderable, PropertyListenable, Rotatable {
    public static final String HEADING       = "heading";
    public static final String HEADING_ARRAY = "headingArray";
    public static final String TOP           = "top";
    public static final String TOP_ARRAY     = "topArray";
    public static final String ACTIVE        = "active";
    public static final String POSITION      = "position";
    public static final String VISIBLE       = "visible";
    public static final String IN_GRID       = "inGrid";
    
    private double[] 	heading = new double[] { 0, 0, 1 }, oldHeading= new double[] {Double.NEGATIVE_INFINITY,Double.NEGATIVE_INFINITY,Double.NEGATIVE_INFINITY};
    private double[] 	top 	= new double[] { 0, 1, 0 }, oldTop    = new double[] {Double.NEGATIVE_INFINITY,Double.NEGATIVE_INFINITY,Double.NEGATIVE_INFINITY};
    protected volatile double[] 
	    position = new double[3], 
	    positionAfterLoop = new double[3],
	    oldPosition = new double[]{Double.NEGATIVE_INFINITY,Double.NEGATIVE_INFINITY,Double.NEGATIVE_INFINITY};
    private boolean loopedBefore = false;
    protected double[]  modelOffset= new double[3];
    private final double[]positionWithOffset 
    				= new double[3];
    private boolean	needToRecalcMatrix=true;
    private TR  	tr;
    private boolean 	visible = true;
    private TRFuture<GL33Model>model;
    private int[] 	triangleObjectDefinitions;
    private int[] 	transparentTriangleObjectDefinitions;
    protected Integer 	matrixID;
    private volatile WeakReference<SpacePartitioningGrid> containingGrid;
    private ArrayList<Behavior> 	inactiveBehaviors  = new ArrayList<Behavior>();
    private ArrayList<CollisionBehavior>collisionBehaviors = new ArrayList<CollisionBehavior>();
    private ArrayList<Behavior> 	tickBehaviors 	   = new ArrayList<Behavior>();
    private boolean 			active 		   = true;
    private byte 			renderFlags=0;
    private boolean			immuneToOpaqueDepthTest  = false;
    //private boolean                     objectDefsInitialized = false;
    private boolean                     inGrid = false;

    protected final double[] aX 	= new double[3];
    protected final double[] aY 	= new double[3];
    protected final double[] aZ 	= new double[3];
    protected final double[] rotTransM 	= new double[16];
    protected final double[] camM 	= new double[16];
    protected final double[] rMd 	= new double[16];
    protected final double[] tMd 	= new double[16];
    protected 	    double[] cMd 	= new double[16];
    private boolean respondToTick	= true;
    private double scale                = 1.;
    private final ReentrantLock         lock = new ReentrantLock();
    private String debugName            = "[unnamed]";
    
    //Cache
    private       GPU                    gpu;
    private       MatrixWindow           matrixWindow;<commit_msg>✔Set renderFlags to volatile. Affects #153.<commit_after>/*******************************************************************************
 * This file is part of TERMINAL RECALL
 * Copyright (c) 2012-2016 <NAME>
 * Part of the jTRFP.org project
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Public License v3.0
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/gpl.html
 * 
 * Contributors:
 *     chuck - initial API and implementation
 ******************************************************************************/
package org.jtrfp.trcl.obj;

import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.concurrent.Callable;
import java.util.concurrent.locks.ReentrantLock;

import org.apache.commons.math3.exception.MathArithmeticException;
import org.apache.commons.math3.geometry.euclidean.threed.Vector3D;
import org.jtrfp.trcl.MatrixWindow;
import org.jtrfp.trcl.ObjectDefinitionWindow;
import org.jtrfp.trcl.PrimitiveList;
import org.jtrfp.trcl.SpacePartitioningGrid;
import org.jtrfp.trcl.Submitter;
import org.jtrfp.trcl.WeakPropertyChangeSupport;
import org.jtrfp.trcl.beh.Behavior;
import org.jtrfp.trcl.beh.BehaviorNotFoundException;
import org.jtrfp.trcl.beh.CollisionBehavior;
import org.jtrfp.trcl.coll.CollectionActionDispatcher;
import org.jtrfp.trcl.coll.PropertyListenable;
import org.jtrfp.trcl.core.Features;
import org.jtrfp.trcl.core.NotReadyException;
import org.jtrfp.trcl.core.TRFactory;
import org.jtrfp.trcl.core.TRFactory.TR;
import org.jtrfp.trcl.core.TRFuture;
import org.jtrfp.trcl.core.TRFutureTask;
import org.jtrfp.trcl.ext.tr.GPUFactory.GPUFeature;
import org.jtrfp.trcl.game.RedFlashFactory.RedFlash;
import org.jtrfp.trcl.gpu.GL33Model;
import org.jtrfp.trcl.gpu.GPU;
import org.jtrfp.trcl.gpu.RenderList;
import org.jtrfp.trcl.gpu.Renderer;
import org.jtrfp.trcl.math.Mat4x4;
import org.jtrfp.trcl.math.Vect3D;
import org.jtrfp.trcl.math.Vect3D.ZeroNormException;
import org.jtrfp.trcl.mem.VEC4Address;

public class WorldObject implements PositionedRenderable, PropertyListenable, Rotatable {
    public static final String HEADING       = "heading";
    public static final String HEADING_ARRAY = "headingArray";
    public static final String TOP           = "top";
    public static final String TOP_ARRAY     = "topArray";
    public static final String ACTIVE        = "active";
    public static final String POSITION      = "position";
    public static final String VISIBLE       = "visible";
    public static final String IN_GRID       = "inGrid";
    
    private double[] 	heading = new double[] { 0, 0, 1 }, oldHeading= new double[] {Double.NEGATIVE_INFINITY,Double.NEGATIVE_INFINITY,Double.NEGATIVE_INFINITY};
    private double[] 	top 	= new double[] { 0, 1, 0 }, oldTop    = new double[] {Double.NEGATIVE_INFINITY,Double.NEGATIVE_INFINITY,Double.NEGATIVE_INFINITY};
    protected volatile double[] 
	    position = new double[3], 
	    positionAfterLoop = new double[3],
	    oldPosition = new double[]{Double.NEGATIVE_INFINITY,Double.NEGATIVE_INFINITY,Double.NEGATIVE_INFINITY};
    private boolean loopedBefore = false;
    protected double[]  modelOffset= new double[3];
    private final double[]positionWithOffset 
    				= new double[3];
    private boolean	needToRecalcMatrix=true;
    private TR  	tr;
    private boolean 	visible = true;
    private TRFuture<GL33Model>model;
    private int[] 	triangleObjectDefinitions;
    private int[] 	transparentTriangleObjectDefinitions;
    protected Integer 	matrixID;
    private volatile WeakReference<SpacePartitioningGrid> containingGrid;
    private ArrayList<Behavior> 	inactiveBehaviors  = new ArrayList<Behavior>();
    private ArrayList<CollisionBehavior>collisionBehaviors = new ArrayList<CollisionBehavior>();
    private ArrayList<Behavior> 	tickBehaviors 	   = new ArrayList<Behavior>();
    private boolean 			active 		   = true;
    private volatile byte 		renderFlags=0;
    private boolean			immuneToOpaqueDepthTest  = false;
    //private boolean                     objectDefsInitialized = false;
    private boolean                     inGrid = false;

    protected final double[] aX 	= new double[3];
    protected final double[] aY 	= new double[3];
    protected final double[] aZ 	= new double[3];
    protected final double[] rotTransM 	= new double[16];
    protected final double[] camM 	= new double[16];
    protected final double[] rMd 	= new double[16];
    protected final double[] tMd 	= new double[16];
    protected 	    double[] cMd 	= new double[16];
    private boolean respondToTick	= true;
    private double scale                = 1.;
    private final ReentrantLock         lock = new ReentrantLock();
    private String debugName            = "[unnamed]";
    
    //Cache
    private       GPU                    gpu;
    private       MatrixWindow           matrixWindow;
{'fraction_non_alphanumeric': 0.11940298507462686, 'fraction_numerical': 0.009651741293532337, 'mean_word_length': 3.90771484375, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '2134767', 'n_tokens_mistral': 3138, 'n_tokens_neox': 2974, 'n_words': 725}