Subversion Repository Public Repository

Nextrek

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
package min3d.core;

import java.util.ArrayList;

import min3d.Shared;
import min3d.vos.TextureVo;

/**
 * Manages a list of TextureVo's used by Object3d's.
 * This allows an Object3d to use multiple textures. 
 * 
 * If more textures are added than what's supported by the hardware  
 * running the application, the extra items are ignored by Renderer
 * 
 * Uses a subset of ArrayList's methods. 
 */
public class TextureList  
{
	private ArrayList<TextureVo> _t;
	
	
	public TextureList()
	{
		_t = new ArrayList<TextureVo>();
	}
	
	/**
	 * Adds item to the list 
	 */
	public boolean add(TextureVo $texture)
	{
		if (! Shared.textureManager().contains($texture.textureId)) return false;
		return _t.add($texture);
	}
	
	/**
	 * Adds item at the given position to the list 
	 */
	public void add(int $index, TextureVo $texture)
	{
		_t.add($index, $texture);
	}
	
	/**
	 * Adds a new TextureVo with the given textureId to the list, and returns that textureVo  
	 */
	public TextureVo addById(String $textureId)
	{
		if (! Shared.textureManager().contains($textureId)) {
			throw new Error("Could not create TextureVo using textureId \"" + $textureId + "\". TextureManager does not contain that id.");
		}
		
		TextureVo t = new TextureVo($textureId);
		_t.add(t);
		return t;
	}
	
	/**
	 * Adds texture as the sole item in the list, replacing any existing items  
	 */
	public boolean addReplace(TextureVo $texture)
	{
		_t.clear();
		return _t.add($texture);
	}
	
	/**
	 * Removes item from the list 
	 */
	public boolean remove(TextureVo $texture)
	{
		return _t.remove($texture);
	}
	
	/**
	 * Removes item with the given textureId from the list 
	 */
	public boolean removeById(String $textureId)
	{
		TextureVo t = this.getById($textureId);
		if (t == null) {
			throw new Error("No match in TextureList for id \"" + $textureId + "\"");
		}
		return _t.remove(t);
	}
	
	public void removeAll()
	{
		for (int i = 0; i < _t.size(); i++)
			_t.remove(0);
	}
	
	/**
	 * Get item from the list which is at the given index position 
	 */
	public TextureVo get(int $index)
	{
		return _t.get($index);
	}
	
	/**
	 * Gets item from the list which has the given textureId
	 */
	public TextureVo getById(String $textureId)
	{
		for (int i = 0; i < _t.size(); i++) {
			String s = _t.get(i).textureId;
			if ($textureId == s) {
				TextureVo t = _t.get(i);
				return t;
			}
		}
		return null;
	}
	
	public int size()
	{
		return _t.size();
	}
	
	public void clear()
	{
		_t.clear();
	}
	
	/**
	 * Return a TextureVo array of TextureList's items 
	 */
	public TextureVo[] toArray()
	{
		Object[] a = _t.toArray();
		TextureVo[] ret = new TextureVo[a.length];
		for (int i = 0; i < _t.size(); i++)
		{
			ret[i] = (TextureVo)_t.get(i);
		}
		return ret;
	}
	
	/**
	 * Returns a String Array of the textureIds of each of the items in the list 
	 */
	public String[] getIds()
	{
		// BTW this makes a casting error. Why?
		// (TextureVo[])_t.toArray();

		String[] a = new String[_t.size()];
		for (int i = 0; i < _t.size(); i++)
		{
			a[i] = _t.get(i).textureId;
		}
		return a;
	}
}

Commits for Nextrek/Android/LibrerieNextrek/src/min3d/core/TextureList.java

Diff revisions: vs.
Revision Author Commited Message
4 FMMortaroli picture FMMortaroli Fri 19 Apr, 2013 16:54:38 +0000