Crossfire JXClient, Trunk
FaceCache.java
Go to the documentation of this file.
1 /*
2  * This file is part of JXClient, the Fullscreen Java Crossfire Client.
3  *
4  * JXClient is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * JXClient is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with JXClient; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17  *
18  * Copyright (C) 2005-2008 Yann Chachkoff
19  * Copyright (C) 2006-2017,2019-2023 Andreas Kirschbaum
20  * Copyright (C) 2010-2012,2014-2018,2020-2023 Nicolas Weeger
21  */
22 
23 package com.realtime.crossfire.jxclient.faces;
24 
25 import java.util.Arrays;
26 import org.jetbrains.annotations.NotNull;
27 import org.jetbrains.annotations.Nullable;
28 
33 public class FaceCache {
34 
38  @Nullable
39  private final Face @NotNull [] faces = new Face[65536];
40 
44  public FaceCache() {
45  faces[0] = new Face(0, "empty", 0);
46  }
47 
52  public void addFace(@NotNull final Face face) {
53  faces[face.getFaceNum()] = face;
54  }
55 
61  @NotNull
62  public Face getFace(final int faceNum) {
63  final Face face = faces[faceNum];
64  if (face != null) {
65  return face;
66  }
67 
68  System.err.println("Warning: accessing undefined face "+faceNum);
69  faces[faceNum] = new Face(faceNum, "face#"+faceNum, 0);
70  return faces[faceNum];
71  }
72 
77  public void reset() {
78  Arrays.fill(faces, null);
79  faces[0] = new Face(0, "empty", 0);
80  }
81 
89  public void addFace(final int faceNum, final int faceSetNum, final int faceChecksum, @NotNull final String faceName) {
90  // XXX: ignores faceSetNum
91  if (faces[faceNum] != null) {
92  System.err.println("Warning: defining duplicate face "+faceNum+" ("+faceName+")");
93  }
94  faces[faceNum] = new Face(faceNum, faceName, faceChecksum);
95  }
96 
97 }
com.realtime.crossfire.jxclient.faces.FaceCache.reset
void reset()
Definition: FaceCache.java:77
com.realtime.crossfire.jxclient.faces.FaceCache.addFace
void addFace(@NotNull final Face face)
Definition: FaceCache.java:52
com.realtime.crossfire.jxclient.faces.FaceCache.getFace
Face getFace(final int faceNum)
Definition: FaceCache.java:62
com.realtime.crossfire.jxclient.faces.FaceCache.faces
final Face[] faces
Definition: FaceCache.java:39
com.realtime.crossfire.jxclient.faces.FaceCache.addFace
void addFace(final int faceNum, final int faceSetNum, final int faceChecksum, @NotNull final String faceName)
Definition: FaceCache.java:89
com.realtime.crossfire.jxclient.faces.FaceCache
Definition: FaceCache.java:33
com.realtime.crossfire.jxclient.faces.FaceCache.FaceCache
FaceCache()
Definition: FaceCache.java:44
com.realtime.crossfire.jxclient.faces.Face
Definition: Face.java:37