Java-Gaming.org Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (756)
Games in Android Showcase (229)
games submitted by our members
Games in WIP (842)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
   Home   Help   Search   Login   Register   
  Show Posts
Pages: [1] 2
1  Game Development / Game Play & Game Design / Item database architecture on: 2018-05-04 06:42:23
So, for a little project I'm working on, I've been thinking about an item database architecture.

I have a base class, Item.  I've merely included the code for the fields; the rest of the class is merely getters and setters, and a basic constructor.

1  
2  
3  
4  
5  
6  
7  
8  
// Item name & description.
   private String name, desc;
   
   // Cost per unit.
   private long baseValuePerUnit;
   
   // Size in meters cubed per unit.
   private float sizePerUnitInM3;


That lays the groundwork for commodity-type items just fine - although it'll be fun figuring out actual mathematically-correct values.  A couple examples:

1  
2  
   Item i1 = new Item("Mattress", "A mattress for sleeping on.", 200, 3.5f, false);
   Item i2 = new Item("Iron Ore", "Unrefined iron-bearing ore.", 75, 0.001f, true);


There will be other kinds of items besides basic commodities, however, each with their own sort of information needed:
> Fuel, requires information on energy density, etc.
> Equipment, such as armor plating, shield generators, etc.
   > Each kind of equipment would require its own unique set of data
      > Armor plating: thermal rating, kinetic rating, etc.
      > Shield generator: thermal rating, kinetic rating, etc.

Now, I'm not a fan of inheritance.  I would really like to avoid it.

To that end, I wanted to ask the folks of JGO, what's your take?

My first idea was to put one of these in there:

1  
   private HashMap<String, Object> addedFields;


and then create a bunch of helper methods.

The other idea I had is to design a sort of super light-weight component system for the items, and then construct unique items via composition.

If you know of any design architectures that could work here, I'd love to hear.  This is less of a question on "Hey, how do I do this exactly" and more of "Hey, what's your thoughts and own experience on this sort of thing."  Links to working examples of open source code are also most welcome!
2  Game Development / Newbie & Debugging Questions / Re: Orthographic projection matrix? on: 2018-04-23 22:05:40
I uh, I figured out what it was.

I forgot to actually bind the shader before attempting to set the uniforms...

Oops.
3  Game Development / Newbie & Debugging Questions / Orthographic projection matrix? on: 2018-04-21 00:20:32
Hello JGO, this one's pretty simple:

I have the basics of a 2d batch drawer.  Currently there are no projection, view, or model matrices involved, which I'm attempting to fix today.

I changed the shader from this:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
#version 330

layout (location=0) in vec2 inPosition;
layout (location=1) in vec2 inTexCoord;

out vec2 vTexCoord;

void main() {
   gl_Position = vec4(inPosition, 0.0, 1.0);
   vTexCoord = inTexCoord;
}



To this:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
#version 330

layout (location=0) in vec2 inPosition;
layout (location=1) in vec2 inTexCoord;

out vec2 vTexCoord;

uniform mat4 projectionMatrix;

void main() {
   gl_Position = projectionMatrix * vec4(inPosition, 0.0, 1.0);
   vTexCoord = inTexCoord;
}


And I then supplied the shader with a bog-standard JOML matrix4f:

1  
2  
3  
4  
Matrix4f proj = new Matrix4f();
proj.identity().setOrtho(0, window.getWidth(), 0, window.getHeight(), -1f, 1f);
shader.setUniform("projectionMatrix", proj);
glViewport(0, 0, window.getWidth(), window.getHeight());


Now, no matter what corners or sizes of quads I supply, I don't get anything rendered on the screen.

Am I missing something obvious here?

EDIT:

In the interest of providing a bit more insight, here is the code for the batcher:

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  
156  
157  
158  
159  
160  
161  
162  
163  
164  
165  
166  
167  
168  
169  
170  
171  
172  
173  
174  
175  
176  
177  
178  
179  
180  
181  
182  
183  
184  
185  
186  
187  
188  
189  
190  
191  
192  
193  
194  
195  
196  
197  
198  
199  
200  
201  
202  
203  
204  
205  
206  
207  
208  
209  
210  
211  
212  
213  
214  
215  
216  
217  
218  
219  
220  
221  
222  
223  
224  
225  
226  
227  
228  
229  
230  
231  
232  
package com.eli.game.render;

import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.opengl.GL15.*;
import static org.lwjgl.opengl.GL20.*;
import static org.lwjgl.opengl.GL30.*;

import java.nio.FloatBuffer;
import java.nio.IntBuffer;

import org.joml.Matrix4f;
import org.joml.Vector2f;
import org.lwjgl.system.MemoryUtil;

public class Batcher {

   private int vaoID;

   private int indID, posID, texID;
   private FloatBuffer posBuf;
   private FloatBuffer texBuf;

   private ShaderProgram shader;
   
   Matrix4f ortho;

   private boolean drawing;
   private int drawCount;

   public void init(int quadsPerBatch, Window window) {

      // create VAO
      vaoID = glGenVertexArrays();
      glBindVertexArray(vaoID);

      // Create index buffer, and initialize values; draw order won't be changing.
      int[] indices = new int[quadsPerBatch * 6]; // # quads * 6 indices per quad, 3 per triangle
      int j = 0;
      for (int i = 0; i < indices.length; i+=6, j+=4) {
         indices[i + 0] = j + 0;
         indices[i + 1] = j + 1;
         indices[i + 2] = j + 2;
         indices[i + 3] = j + 3;
         indices[i + 4] = j + 0;
         indices[i + 5] = j + 2;
      }
      indID = glGenBuffers();
      IntBuffer ib = MemoryUtil.memAllocInt(indices.length);
      ib.put(indices).flip();
      glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indID);
      glBufferData(GL_ELEMENT_ARRAY_BUFFER, ib, GL_DYNAMIC_DRAW);
      MemoryUtil.memFree(ib);

      // create position buffer
      posID = glGenBuffers();
      glBindBuffer(GL_ARRAY_BUFFER, posID);
      posBuf = MemoryUtil.memAllocFloat(quadsPerBatch * 4 * 2); // # quads * 4 verts per quad * 2 attribs per vert
      long size = posBuf.capacity() * Float.BYTES;
      glBufferData(GL_ARRAY_BUFFER, size, GL_DYNAMIC_DRAW);
      glVertexAttribPointer(0, 2, GL_FLOAT, false, 0, 0);

      // Create texture buffer
      texID = glGenBuffers();
      glBindBuffer(GL_ARRAY_BUFFER, texID);
      texBuf = MemoryUtil.memAllocFloat(quadsPerBatch * 4 * 2); // # quads * 4 verts per quad * 2 attribs per vert
      size = texBuf.capacity() * Float.BYTES;
      glBufferData(GL_ARRAY_BUFFER, size, GL_DYNAMIC_DRAW);
      glVertexAttribPointer(1, 2, GL_FLOAT, false, 0, 0);

      glBindBuffer(GL_ARRAY_BUFFER, 0);
     
      // Initialize variables
      drawCount = 0;
      drawing = false;

      // Load shader
      shader = new ShaderProgram();
      shader.loadVertexShader("./resources/shaders/basic/basic.vs");
      shader.loadFragmentShader("./resources/shaders/basic/basic.fs");
      shader.link();

      // Create and set shader uniforms
      shader.createUniform("texture_sampler");
      shader.createUniform("projectionMatrix");
      shader.setUniform("texture_sampler", 0);
     
      ortho = new Matrix4f();
      ortho.identity().setOrtho(0, window.getWidth(), 0, window.getHeight(), -1f, 1f);
      shader.setUniform("projectionMatrix", ortho);
      glViewport(0, 0, window.getWidth(), window.getHeight());

      glEnable(GL_BLEND);
      glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
   }

   public void clear() {
      glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
   }

   public void begin() {
      if (drawing) {
         throw new IllegalStateException("Already drawing.");
      }
      drawing = true;
      drawCount = 0;
   }

   public void end() {
      if (!drawing) {
         throw new IllegalStateException("Not drawing.");
      }
      drawing = false;
      flush();
   }

   /** Flush data to GPU and render. */
   public void flush() {

      // Only flush if there's information *to* flush.
      if (drawCount > 0) {

         // Bind VAO
         glBindVertexArray(vaoID);
         
         // Flip position buffer, and send to GPU
         posBuf.flip();
         glBindBuffer(GL_ARRAY_BUFFER, posID);
         glBufferSubData(GL_ARRAY_BUFFER, 0, posBuf);
         glVertexAttribPointer(0, 2, GL_FLOAT, false, 0, 0);

         // Flip texture buffer, and send to GPU
         texBuf.flip();
         glBindBuffer(GL_ARRAY_BUFFER, texID);
         glBufferSubData(GL_ARRAY_BUFFER, 0, texBuf);
         glVertexAttribPointer(1, 2, GL_FLOAT, false, 0, 0);

         // Bind shader
         shader.bind();
         
         // Set texture
         shader.setUniform("texture_sampler", 0);
         
         // Enable necessary vertex attributes, draw the data, and restore state.
         glEnableVertexAttribArray(0);
         glEnableVertexAttribArray(1);

         glDrawElements(GL_TRIANGLES, drawCount, GL_UNSIGNED_INT, 0);

         glDisableVertexAttribArray(0);
         glDisableVertexAttribArray(1);

         // Unbind VAO
         glBindVertexArray(0);
         
         // Clear vertices for next batch
         posBuf.clear();
         texBuf.clear();
         drawCount = 0;
      }
   }
   
   public void drawPolarRect(TextureRegion tex, float elevation, float height, float startAngle, float endAngle) {

      if (posBuf.remaining() < 2 * 4 * 2) { // 2 vertex attribs, 4 vertices, 2 components per vert
         System.out.println("Not enough data remaining in VBO, flushing.");
         flush();
      }

      float angle1 = (float) Math.toRadians(startAngle); // lesser angle
      float angle2 = (float) Math.toRadians(endAngle); // greater angle

      // Draw order:

      //  0     1--0
      //  |\     \ |
      //  | \     \|
      //  1--2     2

      // top left (greater angle, larger radius)
      posBuf.put((float) Math.cos(angle2) * (elevation + height));
      posBuf.put((float) Math.sin(angle2) * (elevation + height));

      // bottom left (greater angle, smaller radius)
      posBuf.put((float) Math.cos(angle2) * elevation);
      posBuf.put((float) Math.sin(angle2) * elevation);

      // bottom right (smaller angle, smaller radius)
      posBuf.put((float) Math.cos(angle1) * elevation);
      posBuf.put((float) Math.sin(angle1) * elevation);

      // top right (smaller angle, greater radius
      posBuf.put((float) Math.cos(angle1) * (elevation + height));
      posBuf.put((float) Math.sin(angle1) * (elevation + height));

      // Textures
      texBuf.put(tex.getU1()).put(tex.getV2());
      texBuf.put(tex.getU1()).put(tex.getV1());
      texBuf.put(tex.getU2()).put(tex.getV1());
      texBuf.put(tex.getU2()).put(tex.getV2());

      drawCount += 6;
   }

   public void drawQuad(Vector2f topLeft, Vector2f bottomLeft, Vector2f bottomRight, Vector2f topRight, float u1, float u2, float v1, float v2) {

      posBuf.put(topLeft.x).put(topLeft.y);
      posBuf.put(bottomLeft.x).put(bottomLeft.y);
      posBuf.put(bottomRight.x).put(bottomRight.y);
      posBuf.put(topRight.x).put(topRight.y);

      texBuf.put(u1).put(v2);
      texBuf.put(u1).put(v1);
      texBuf.put(u2).put(v1);
      texBuf.put(u2).put(v2);

      drawCount += 6;
   }
   
   public void drawQuad(float x, float y, float width, float height, float u1, float u2, float v1, float v2) {
      posBuf.put(x)         .put(y + height);
      posBuf.put(x)         .put(y);
      posBuf.put(x + width)   .put(y);
      posBuf.put(x + width)   .put(y + height);
     
      texBuf.put(u1).put(v2);
      texBuf.put(u1).put(v1);
      texBuf.put(u2).put(v1);
      texBuf.put(u2).put(v2);
     
      drawCount += 6;
   }
}
4  Java Game APIs & Engines / Java 2D / Re: First time pixel artist on: 2018-01-16 06:36:39
This is purely from the standpoint of someone who enjoys their straight lines & hard corners:  the window on the left of the building looks a little off.  Other than that, I actually find myself enjoying the setup you have going here!

If I might make a suggestion (it certainly made sense and helped me when someone pointed it out) I learned how to use Blender for incredibly basic stuff, and it really helped me to start drawing things with accurate perspective.  Maybe something like that can also help you along?

In any case, fine work there, chief.
5  Discussions / General Discussions / Re: Gosh, it's quiet in here on: 2017-11-09 03:46:39
I'm not a particularly notable member here on JGO, I dabbled in a few bits here and there, but my accomplishments amount to getting basic 3D rendering running on a self-coded engine.

But that being said, I'd just like to chip in my two cents; whatever is decided here, I will certainly be there to keep it from complete emptiness.  I could even help develop some material for a potential new site to help keep new members around.  Y'know, tutorials and the like.

I have fond memories of this site, and the people on it - you're all good folks.
6  Game Development / Newbie & Debugging Questions / Re: How would you do this? on: 2017-05-05 05:48:29
If you can manage to restrict access to the actual values via private modifiers, getters, setters, and that sort (Though reflection may bypass this), then you could check for legal moves in the Deck.

Perhaps store a pre-modification copy of Deck, and check to make sure only the thing that was supposed to happen, happened.  Dunno how you'd make sure that you can't get at the copy though.

I.E. if you play 1 card that doesn't do anything beyond subtracting that card from the deck, if anything else changes, you know something's up, and you can replace the deck with the correct one and, I dunno, I guess you'd first inform the player that an illegal move was made, and if it keeps happening, penalize them more and more, until the other person just wins by forfeit?

Again, there are probably ways around this (there are ALWAYS ways around security, no matter how obscure).  I just figured I'd toss in my two cents.
7  Games Center / Cube World Projects / Re: [LWJGL] [JOML] Some instancing queries on: 2017-05-05 05:28:47
My own little voxel project, though I've not touched it for a long time, renders blocks by constructing a single mesh for the entire chunk (32 blocks per axis), using a greedy-meshing algorithm, combining any similar blocks next to each other into larger quads with texture coordinates to match.  For example, an even plane of stone blocks is rendered as 6 quads, and looks just fine.

My voxels need several things.  Texture, vertex color, and maybe normal mapping if I ever get around to that.  There are pre-set values for baking the most rudimentary of lighting onto them.  For example, if a block's top face has the color of (1, 1, 1, 1), then the "north" face will be (0.7, 0.7, 0.7, 0.7) to help see the block shapes.  That's probably not going to stay forever, but it helps enormously for now.  For now, animated textures are outside the realm of what I need, except for on special blocks, which are their own case.  I also haven't yet done any lighting or shadows except for the basic stuff described above.

I've seen talk of using 6 VBO's, one for each set of faces, IE a "north-face" vbo, etc, and you'd only ever have to draw three of them at once (How are you going to see the top and bottom of a block all at once?  That'd be weird).  That might be worthwhile, but I've yet to implement such a thing, though the greedy meshing I use is a prime candidate since each set of faces is computed in a separate sweep anyway.

Though, since having to regenerate them each frame when checking in what direction the player is looking sounds bad, you'd probably need to generate all 6 VBO's in advance, and select which ones to render.  Whether or not the performance gained from not drawing the entire chunk geometry in one draw call, vs the overhead from drawing 3 VBO's, is a question I've no answer to, though I'm sure there are very smart folks around who could tell you.  I'll probably try and profile each method myself to figure that out, it's rather intriguing.

It's even murkier if you're doing transparency stuff too.  I don't know how it's done the "recommended" way; I just generate another set of geometry for the transparent stuff, since I've not the foggiest idea how to do transparent and opaque blocks in the same set of geometry.  It's probably possible, but not by such a plebian person as myself.  My first guess is geometry shading plus some sort of binary value, but I really don't know.

Using instancing to render the blocks themselves, from what I'm getting here, seems a little odd.  Not wrong, never wrong, just not a use-case that I've ever considered.

For me, I store 1 short per normal terrain block in a big 1D array, which I access using a hashing function.  That means there can be a little over 30 thousand different block types in the world, more if I used unsigned shorts.  I think that'd be like 65536 different types?  Plenty, even if people ever picked up modding for it.  Whether or not that is actually more space efficient, I don't know; I remember reading that Java uses 32 bits for each value anyway.  Plus, the whole having to cast to shorts probably doesn't help, though there's probably a more effective method lurking on the internet.

32 x 32 x 32 shorts for tile IDs, 3 integers for the chunk index, and a pointer to the parent "grid" make up a Chunk.  If / when I get around to it, each Chunk may contain a list of their own self-contained, so-called "tile entities" I.E. a furnace, and if that chunk ever gets unloaded while working, when it's reloaded, you can calculate the work it was supposed to have done while away.  So, at the very least, a Chunk takes up 66~ ish kilobytes.

That ain't so bad!  Though if I ever have rotate-able blocks, I'll need to start storing rotation data for them, which I'll endeavor to have no more than double the size of the chunk.  Should be well within the realm of possibility, and 132~ kb / chunk is... well, it isn't amazing, but it'll work faster than if I were to pack everything as close together as possible.  Hashing and bit manipulation probably costs more than it's worth at that point.

A Grid contains a unique identifier name, and a HashMap<Vector3i, Chunk> map of chunks.  It's easy to figure out chunks, since I'd just divide and round down any in-world position by 32, and that would give me chunk indices.  So if my player is at (20, 20, 20), he's in chunk (0, 0, 0) and, in-chunk, he's at (20, 20, 20).  It even works for negative indices if you fiddle with the hashing function, something that I thought was taken for granted but apparently is not; if he were at (-1, -1, -1) then a lot of the time the calculation would put him in (0, 0, 0) when he should actually be at chunk (-1, -1, -1), in-chunk (31, 31, 31).  Rounding has a lot to do with it, as well as integer division.  I've not yet figured out the correct hashing function so it always works, but I'm getting there.

Loading and unloading chunks to-disk is easy as checking their distance from where the player is; if the chunk's too far away, unload it.  However, if there are any special blocks that are doing work, save their current progress so you can calculate what needs to happen the next time that chunk is loaded.  It might also be an idea to unload chunks that haven't had any change happen to them for a certain amount of time, but keep the mesh; upon the player re-entering, or upon the modification of such a chunk, record the changes, reload it, apply the changes, and continue as usual.

For example, a giant bomb going off far away would need to make changes, so you could design a slower-paced solver for that bomb blast, have it trudge along so it doesn't slow down the actual action zone, and when it's done, unload everything.  Or, if the player gets close enough that the job needs to be finished, switch over to a faster solver.  Perhaps modify the speed based on how far away the player is.

I digress.  And it'll happen again, probably.  ANYWAYS!

The worst-case scenario for meshing means I'm generating 6 quads per block, I.E. a 3D checkerboard of glass and stone where there are the maximum number of visible faces possible, since there'd be two worst-case scenarios, one for opaque blocks, and another for transparent.  That's fine, I'm pretty sure something like that is literally unavoidable for such a situation, and is incredibly unlikely to occur in normal play.

Special blocks, like a furnace or something, would probably be handled with instancing, as they're a higher-poly model, and I can supply the shader with a series of positions and rotations, probably condensed down into as little information as possible.  Or a transformation matrix, that could work.  If this is the sort of thing you're trying to figure out, then:

My matrix math is rough at best, and I really need to work on that.  However, I'm sure you can find that information on google somewhere, on how to create a transformation matrix.  Keeping a list of "special" blocks and their positions and orientations, and sending that data to be instanced, should be very possible.  Each matrix would need to be constructed with one position and one orientation, yeah?

For position, a couple floats would probably be fine, X Y and Z.  For rotation, 2 bits per axis, 0 being 0 degrees, with 1 being 90, 2 being 180, and 3 being 270, would probably work, and you can supply that in the form of a byte with 2 dummy bits at the end you can ignore.  YMMV on that one, I've not done a ton with memory packing like this, though it seems promising or at least worth investigating.  Maybe using another float would be a good idea.

Constructing the matrix in the shader might be worthwhile.  From what I've read about recent technology, the GPU has a ridiculous amount of horsepower at its disposal that the CPU does not, and that may be one of those calculation-heavy tasks that the CPU would struggle with that the GPU would be fine with.  I'd recommend testing both methods; in-shader and out.

The big thing I always seem to consider is, "Is it worth the processing to figure out exactly which set of voxel faces what needs rendering?"  Each face is 2 quads, it can't hurt that much to be a little more efficient with CPU to have a few extra triangles for the GPU.

Bear in mind, I've not touched the thing for a year and a half.  The trends and methodology for rendering voxels might have evolved since then.

However, for some specs, I can render a space of 8x8x8 chunks, which is... 16,777,216 blocks in volume, 256 blocks per edge, and it does rather well.  I've not even gotten into culling the chunks that are underground, that you wouldn't even be able to see anyway, so the overhead from their draw calls and 6 quads are included in that too.

Further optimizations may include the whole 6 vbo deal, and when tile entities come around, raycasting or frustum culling to make sure that they're visible will eliminate the ones that aren't.  You could even frustum cull chunks too.

Another way it just occurred to me, for the 6 vbo deal, is to only have 1 VBO and to put all the data you need into it, and just render a subset of that data for each face that's visible.  Might be worthwhile.

I get rather excited about these things and waffle on a great deal.  I'm no authority on the subject, but there's some stuff I've been reading that might help:

https://lwjglgamedev.gitbooks.io/3d-game-development-with-lwjgl/content/
That's what I'm using to help build from the ground up, since I wanted my own engine!  Maybe a bit ambitious, but hey, it's fun to learn. Cool

http://www.sea-of-memes.com/summary/blog_parts.html
A very interesting blog that has a bit of a disjointed deal to its progress, but still fun and engaging to read!

Plus various articles I found by googling everything under the sun about voxels.

Hope this was at the very least informative, if not actually helpful!   Grin
8  Game Development / Newbie & Debugging Questions / LibGDX project setup? on: 2016-07-26 13:40:24
Is it possible to have LibGDX only create one project?  And if so, how would I go about doing that?
9  Game Development / Newbie & Debugging Questions / How to efficiently store values, and benefit? on: 2016-02-22 19:50:23
Essentially, I have an array of 3 sets of values, 0-3.  I can store the 4 values in 2 bits, yeah?  And each 3 values are related to each other - they represent rotation on X, Y, or Z.  My question is, how would I go about storing these values in a single container in an array - preferably not a class as those add overhead?

Also, is there a gain in performance to storing and getting the values from these bits?  Right now, I'm storing the values in a 4-dimensional byte array, as I have a 3D array of 3 values for each X, Y, and Z in space.  I might just be jumping the gun, but this seems like bad practice to me.  I've considered writing a utility class that uses a BitSet, but I've heard that those aren't all they're cracked up to be, simple though it might be.

For the former, original question, what I have boiled it down to is that I need to use bitshifting (> and <) as well as masking AND and OR in order to shift.

1  
2  
3  
4  
5  
6  
7  
8  
public void setBit(byte b, int pos, boolean truth) {
    if (truth) {
        b |= (1 << pos);
    }
    else {
        b &= ~(1 << pos);
    }
}


It's kinda messy and that's only how to SET the bits - I'm still unsure of how to read specific bits.

For the second method with the BitSet, it would be much easier - every six bits = the three 2-bit values, offset by 6 * whatever.  But I don't know if it's a viable method, as the array size that I calculate I need for the values per "chunk" of data is like, ~3KB in bits alone.  It would still be miles easier though... I think?

Sorry if anything is kinda oddly-worded!
10  Games Center / WIP games, tools & toy projects / Re: Pong in Java on: 2016-01-21 23:04:05
Y'know somethin'?  You completed a game.  That puts you ahead of my years of fiddling with stuff but never quite creating something that was, well, y'know, playable.  Even if pong is just pong, it's definitely an excellent first project!
11  Games Center / WIP games, tools & toy projects / Re: Vangard on: 2016-01-19 02:09:28
Maybe the ingredients used in an item can determine whether it's magic?  I mean, a regular iron sword isn't going to be anything incredibly special, but what about one made from a dragon's fang?  What about a set of armor made from woven Warg fur, or the hide of a sea serpent?

Maybe some materials aren't actively magical, but hold the potential for magic much better, like the aforementioned dragon's fang - it would take very well indeed to magic concerning flame, as it has been exposed to dragon's fire for a long time.  The smith might, after years and years of practice, be able to draw out that nature into a blade that spits and hisses with fires whenever it's swung.

But powerful magic may be even further beyond that, requiring divine guidance.  That dragon fang sword that spits fire is impressive, but the smith had guidance - now the blade itself can absorb fire, lob it, even cause an eruption of flames.  Maybe he was even able to recreate the dragon's essence with runework - and the sword summons small fire dragons, or maybe even not-so-small exploding fire dragons.

Depending on how large you want magic to scale, an artifact made of the highest-quality materials, by the greatest of smiths and with guidance from the gods themselves - such an artifact might have some truly insane capabilities.

... On a side note, suggestions are fun!  I had to struggle not to start getting really crazy with the ideas!
12  Games Center / WIP games, tools & toy projects / Re: Vangard on: 2015-10-27 00:51:08
I'm curious as to how you're going about the entities.  Is it an entity system?  Or are you using inheritance / composition?  Whatever it is, it seems very, very cool!
13  Game Development / Newbie & Debugging Questions / World architecture and internal construction? on: 2015-08-02 06:13:04
I have a WorldMap class that currently stores arrays of Rooms, Regions, and Connections, kinda like a big node-looking map.

- Rooms are more broad than a house room, a room can be thought of as any one screen, or one level, but much less complex at the moment.
- Connections connect two Rooms at specific points.  The entrances have specific styles associated with them (fancy, plain, (boss!), etc).
- Regions are simply a bucket of Rooms that will later provide rendering details (styles, etc), so rooms within a Castle region will have brick walls (probably).

My question is, what would JGO recommend when it comes to just how stuff is structured internally?  The ideas I have in mind are:

1. see the above, basically the world is a big bag of everything.  Objects have a global identifier instead of more localized ones.  Arguably with this approach, I could get rid of Regions and instead make rooms self-contained with stuff for styles and traps and everything else.  It feels a lot closer to entity-component-based design at that point, unless I'm crazy, which could potentially work very well for whenever I decide to add dungeon traps and loot and everything else that a game could probably have, since stuff is "decoupled" so to speak.

2. The world stores an array of regions and an array of connections between regions.  The regions store a collection of rooms and a collection of connections between those rooms.  The objects would instead have a local identifier value, instead of one as it would be in the entire world.  This feels more like regular object-orientated, inheritance-like (or at least tree-like), since the tree of objects is world, region, room.  (Connections kinda exist in limbo like branches, whatever)  This approach is kinda nice since I won't have spare rooms floating about that I forget to attach or something.  I also don't want to slip into the mindset that I should try to fit everything into ECS design, because there are some things that I feel just don't quite jive with it.

3.  Kinda weak-feeling, but posted for the sake of completeness:  make each room self-contained, with references to its own paths and the region it is in, along with whatever else might come along.  The only problem is that I feel like this is inefficient, not in an optimization sense, but in the sense that I need to store objects repeatedly in different objects and have multiple references.  It sounds like a web instead of a well-ordered chaos, and potentially very messy.

Any feedback is appreciated!  I'm not looking for hard answers, just for some feedback for those that have likely been doing this for probably quite a bit longer than I have.

[EDIT]:  Now that I think about it, this probably belongs in Game Design.  Kinda muddled.
14  Java Game APIs & Engines / Engines, Libraries and Tools / LibGDX drawing of sprites? on: 2015-04-24 05:17:05
So, I have a grid of tiles I wish to render, along with various other objects and bits / pieces atop those tiles.  I've determined that the way I should go about it is to only render the tiles around the player's position, which isn't too hard.

The thing is, LibGDX's SpriteBatch has a maximum size of 5460 sprites per drawing call, correct?  There might well be more than that at any given point, considering the tiles are 8x8 and the screen is 640 x 480, coming up to 4800 sprites in tiles alone.  On top of those might be items and entities and other such nonsense.

Does anyone have any advice for me, whether to use separate spritebatches or something like that?  Would it be more efficient?  Or can I increase the maximum size of a spritebatch and would THAT be more efficient?

Thanks!
15  Game Development / Newbie & Debugging Questions / Drawing voxel pixels? on: 2015-04-23 00:58:05
So, I've looked at games like Voxatron and that weird little thing that Kevglass made, and I liked his strange 2d-3d voxel pixel things enough that I wanted to create something like it.

So far as I've found, I need a 3d grid of cells, and the cells can be occupied by a kind of block with a color.  However, the way to "cull" the blocks (Not draw those behind others to avoid drawing pixels) escapes me.

For that matter, I've looked into rendering with pixels, and I've seen a couple methods, such as OpenGL's glDrawPixels() method and using a BufferedImage and modifying its RGB buffer.  But both were apparently not very good in the optimization department.  For reference, the area that must be rendered in pixels is 640 x 480.

I can easily create a 3d grid system with chunks (also dubious, but seem necessary) but I'm not sure how to translate 3d grid into the individual pixels.

Can anyone give me any pointers to methods of rendering, and how to implement them?
16  Game Development / Newbie & Debugging Questions / Rotation issue - pointing at a certain point on: 2015-03-01 20:11:45
So, I have code here for rotation of an entity.  This is on LIBGDX, if that's important.

1  
rotation.degrees = (MathUtils.atan2(pos.y - position.y , pos.x - position.x) * MathUtils.radiansToDegrees) - 90;


where pos is the position of the mouse, and position is the entity's position.  The strange thing is that atan2 is returning incorrectly or something, since the values I'm getting are NOT what I need.  It's like, the more I go along the X or Y axis, the more it rotates, but only within 90 degrees or something like that.

What am I doing wrong?  I've looked up several solutions and every single one pointed to this code, or a variant thereof.


EDIT: I fixed the problem.  It turns out that it was not a calculations problem, but rather a rendering problem - I didn't account for the rendering system's offset.
17  Game Development / Newbie & Debugging Questions / Strange issue with recursion? on: 2013-12-28 21:26:07
So essentially, the following snippet of code loops endlessly.

1  
2  
3  
4  
5  
      while (parent != null) {
         System.out.println(parent);
         offset.add(offsetFromParentWithRotation());
         parent = parent.getParent();
      }


Why is that?  Am I not allowed to set the parent like that, or am I missing something very obvious?
18  Game Development / Newbie & Debugging Questions / Re: OOP Noob - Extending Classes, or How Else to Create Unique NPCs? on: 2013-11-16 14:13:03
This may be a bit advanced or a jump to get into, but a component-system based approach is quite efficient, from my own experience.  Essentially, each entity is simply an ID that's assigned predefined component classes - like health, or damage, or movement - that another class, a system or handler, takes into account to make the entity do what you want it to.

The one I like currently is the Artemis Entity System.  http://gamadu.com/artemis/
19  Game Development / Game Play & Game Design / Re: Creating a circular "grid" ? on: 2013-11-16 01:28:32
Abuse has the right idea, and philfrei goes a little more in depth.
20  Game Development / Game Play & Game Design / Re: Creating a circular "grid" ? on: 2013-11-11 16:17:46
I would do it that way, were it not for that you're supposed to be viewing these at all angles - the "up" can be in any direction along this single plane.  But since it's like that, it's supposed to look like everything is going towards the center - if I were to use a square grid in this case, if you were looking at it at a 45 degree angle, everything would be diagonal.
21  Game Development / Game Play & Game Design / Creating a circular "grid" ? on: 2013-11-11 15:55:33
My quest is to essentially create different-sized rings, centered around the same point, that are made of 1-unit pieces.

My problems are that I have difficulty understanding the math required to create such.  I know how to create rings that are made of differing SIZED pieces, like 360 degrees = 360 pieces per ring, but the pieces get progressively larger as you go away from the origin point.  I don't want that - I want the pieces to stay the same size, instead creating more as you go outward.

I was hoping someone would help me figure out how to fix up my code in order to do this.


1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
      float radians = (float) Math.toRadians(degrees);
     
      float[] data = new float[] {};
     
      float circ = MathUtil.getCircumference(depth); // Get the circumference at the chosen depth
      float circt = MathUtil.fastfloor(circ); // Round the circumference
     
      for (int c = 0; c < circt; c++) { // For every 1 "unit" do
         float rads = (float) c / circt; // Dividing the count by the circumference gives us the radian measure for each block
         
      }


That was as far as I had gotten before this made itself clear to my mind.
22  Game Development / Newbie & Debugging Questions / Re: Using LWJGL color API? on: 2013-07-13 03:45:16
Adding this snippet of code to ask:  Am I going about this the correct way?  I need 4 floats (one representing each of r, g, b, a) and they're supposed to be values between 0 and 1.  I'm trying to convert from a hexadecimal integer (eg 0xFFFFFFFF) to the four floats.

1  
2  
3  
4  
5  
6  
7  
8  
   protected float[] getRGBA(int color) {
      return new float[] {
            (color & 0xFF) / 255f,
            (color >> 8 & 0xFF) / 255f,
            (color >> 16 & 0xFF) / 255f,
            (color >> 24 & 0xFF) / 255f
      };
   }


Am I thinking about this the right way?
23  Game Development / Newbie & Debugging Questions / Re: Face culling on voxels. on: 2013-07-13 01:26:48
Ahh, that's actually what I was busy doing.  I eventually figured out the whole access issue, although I'm not sure the method that I went about is correct.

By the way, there is no World class;  each voxel group effectively needs to know about all the voxels it contains.  So i suppose there are many World classes in that respect; the basic group and all of the ones that extend it (so they can behave differently - ie a turret of a ship needs to rotate differently than the ship itself.)  To that end, this is what I've come up with:

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  
   public void updateVBO() {
      int numfaces = 0;
      boolean front = false, back = false, left = false, right = false, top = false, bottom = false;
      for (int x = 0; x < width; x++) {
         for (int y = 0; y < height; y++) {
            for (int z = 0; z < length; z++) {

               if (isOOB(x+1, y, z) || !isOCC(x+1, y, z)) {right = true; numfaces++;}
               if (isOOB(x-1, y, z) || !isOCC(x-1, y, z)) {left = true; numfaces++;}
               if (isOOB(x, y+1, z) || !isOCC(x, y+1, z)) {top = true; numfaces++;}
               if (isOOB(x, y-1, z) || !isOCC(x, y-1, z)) {bottom = true; numfaces++;}
               if (isOOB(x, y, z+1) || !isOCC(x, y, z+1)) {right = true; numfaces++;}
               if (isOOB(x, y, z-1) || !isOCC(x, y, z-1)) {left = true; numfaces++;}

               voxelData(x, y, z, voxels[x][y][z].type, numfaces, front, back, left, right, top, bottom);

            }
         }
      }
   }

   protected boolean isOOB(int x, int y, int z) {
      if (x * y * z > width * height * length || x * y * z < 0) return true;
      return false;
   }
   protected boolean isOCC(int x, int y, int z) {
      if (!isOOB(x, y, z)) if (voxels[x][y][z].opaque) return true;
      return false;
   }


Also, I've refrained from putting data into the actual floatbuffer for now because I don't want the buffer being too big.  That being said, compacting it would work to remove the extra space, right?
24  Game Development / Newbie & Debugging Questions / Re: Using LWJGL color API? on: 2013-07-12 23:19:41
So would I only need 1 color "vertex" when interleaving color with position in my FloatBuffer?  From what it looks like, that seems to be the case.
25  Game Development / Newbie & Debugging Questions / Face culling on voxels. on: 2013-07-12 19:56:41
I have a segment of code here that's supposed to cull faces of voxels that should be invisible.

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  
   private FloatBuffer voxelData(int x, int y, int z) {
      float r = rand.nextFloat(), g = rand.nextFloat(), b = rand.nextFloat();
      float xscale = x * scale, yscale = y * scale, zscale = z * scale;
      int numfaces = 6;

      boolean top = true, bottom = false, left = true, right = true, front = true, back = true;
      if (x != width--  && voxels[x + 1][y][z].isActive) {right = false; numfaces--;}
      if (x != 0         && voxels[x - 1][y][z].isActive) {left = false; numfaces--;}
      if (y != height-- && voxels[x][y + 1][z].isActive) {top = false; numfaces--;}
      if (y != 0         && voxels[x][y - 1][z].isActive) {bottom = false; numfaces--;}
      if (z != length-- && voxels[x][y][z + 1].isActive) {front = false; numfaces--;}
      if (z != 0         && voxels[x][y][z - 1].isActive) {back = false; numfaces--;}

      if (numfaces == 0) return null;

      FloatBuffer data = BufferUtils.createFloatBuffer(numfaces * 24);

      if (top) { data.put(new float[] {
            this.x + xscale + 0.5f * scale,      this.y + yscale + 0.5f * scale,      this.z + zscale - 0.5f * scale,   r, g, b,
            this.x + xscale - 0.5f * scale,      this.y + yscale + 0.5f * scale,      this.z + zscale - 0.5f * scale,   r, g, b,
            this.x + xscale - 0.5f * scale,      this.y + yscale + 0.5f * scale,      this.z + zscale + 0.5f * scale,   r, g, b,
            this.x + xscale + 0.5f * scale,      this.y + yscale + 0.5f * scale,      this.z + zscale + 0.5f * scale,   r, g, b,
      });}

      if (bottom) { data.put(new float[] {
            this.x + xscale - 0.5f * scale,      this.y + yscale - 0.5f * scale,      this.z + zscale - 0.5f * scale,   r, g, b,
            this.x + xscale + 0.5f * scale,      this.y + yscale - 0.5f * scale,      this.z + zscale - 0.5f * scale,   r, g, b,
            this.x + xscale + 0.5f * scale,      this.y + yscale - 0.5f * scale,      this.z + zscale + 0.5f * scale,   r, g, b,
            this.x + xscale - 0.5f * scale,      this.y + yscale - 0.5f * scale,      this.z + zscale + 0.5f * scale,   r, g, b,
      });}

      if (left) { data.put(new float[] {
            this.x + xscale - 0.5f * scale,      this.y + yscale + 0.5f * scale,      this.z + zscale + 0.5f * scale,   r, g, b,
            this.x + xscale - 0.5f * scale,      this.y + yscale + 0.5f * scale,      this.z + zscale - 0.5f * scale,   r, g, b,
            this.x + xscale - 0.5f * scale,      this.y + yscale - 0.5f * scale,      this.z + zscale - 0.5f * scale,   r, g, b,
            this.x + xscale - 0.5f * scale,      this.y + yscale - 0.5f * scale,      this.z + zscale + 0.5f * scale,   r, g, b,
      });}

      if (right) { data.put(new float[] {
            this.x + xscale + 0.5f * scale,      this.y + yscale - 0.5f * scale,      this.z + zscale + 0.5f * scale,   r, g, b,
            this.x + xscale + 0.5f * scale,      this.y + yscale - 0.5f * scale,      this.z + zscale - 0.5f * scale,   r, g, b,
            this.x + xscale + 0.5f * scale,      this.y + yscale + 0.5f * scale,      this.z + zscale - 0.5f * scale,   r, g, b,
            this.x + xscale + 0.5f * scale,      this.y + yscale + 0.5f * scale,      this.z + zscale + 0.5f * scale,   r, g, b,
      });}

      if (front) { data.put(new float[] {
            this.x + xscale + 0.5f * scale,      this.y + yscale + 0.5f * scale,      this.z + zscale + 0.5f * scale,   r, g, b,
            this.x + xscale - 0.5f * scale,      this.y + yscale + 0.5f * scale,      this.z + zscale + 0.5f * scale,   r, g, b,
            this.x + xscale - 0.5f * scale,      this.y + yscale - 0.5f * scale,      this.z + zscale + 0.5f * scale,   r, g, b,
            this.x + xscale + 0.5f * scale,      this.y + yscale - 0.5f * scale,      this.z + zscale + 0.5f * scale,   r, g, b,
      });}

      if (back) { data.put(new float[] {
            this.x + xscale + 0.5f * scale,      this.y + yscale - 0.5f * scale,      this.z + zscale - 0.5f * scale,   r, g, b,
            this.x + xscale - 0.5f * scale,      this.y + yscale - 0.5f * scale,      this.z + zscale - 0.5f * scale,   r, g, b,
            this.x + xscale - 0.5f * scale,      this.y + yscale + 0.5f * scale,      this.z + zscale - 0.5f * scale,   r, g, b,
            this.x + xscale + 0.5f * scale,      this.y + yscale + 0.5f * scale,      this.z + zscale - 0.5f * scale,   r, g, b,
      });}

      data.flip();
      return data;
   }

The segment is passed the x, y, and z values through a triple-nested for-loop checking each voxel in a 3d array.  However, the code seems to only output left and back sides; never any others.  Even then, it's only the left-bottom-back corner that renders, and not even the bottom face; just the back, and three left faces from the edge, and a face one above that.
Here's a screenshot:  
26  Game Development / Newbie & Debugging Questions / Re: About lists and the elements inside of them. on: 2013-07-12 14:45:13
That's actually a very good tip.  However, isn't it sort of misleading when you're going through the interfaces for each component type rather than the actual object itself?

Also, I've abandoned that method of components for now and instead have a basic VoxelGroup class that has an enum of GroupTypes to determine how it should behave (Another class entirely).  The list of voxels from before is non-existant

With that in mind, would your interface method still work properly?  Or should I change my architecture slightly to accomodate?

And the idea of an abstract base class; would that replace the VoxelGroup class, and then I would create multiple classes for different types of groups, all of which would use an interface for commonly needed methods - that about sum it up?
27  Game Development / Newbie & Debugging Questions / Re: Using LWJGL color API? on: 2013-07-12 03:26:24
Indeed, the bytes thing is a good idea.  Could anyone give me a small example of how to convert bytes to a color, though?  It'd be very, very helpful indeed.
28  Game Development / Game Play & Game Design / Re: Intuitive Interface Design on: 2013-07-12 02:15:14
I like design B more.  It positions all the data that the player (Probably) cares about closer together.  The recent screenshot looks really nice, actually.  Oskuro's suggestion is a very good one too.

Perhaps there should be a way to assign hotkeys?  Those are always nice to have.

Also, a purely aesthetic idea, perhaps make it so that the player can change the GUI color?  Grayscale images + color interpretation?
29  Game Development / Game Play & Game Design / Re: Data structure for voxels? on: 2013-07-11 22:52:44
Would I not have to loop through with an array for collisions, then?  If you could explain a little more how a 3d (or even 1d) array wouldn't require looping for collisions, that'd make it a bit easier for me to wrap my head around.

Also, for the if statement, do you mean checking each index in the array like this, sorta?

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
...
for (int x = 0; x < width; x++ {
     for (int y = 0; y < height; y++) {
          for (int z = 0; z < depth; z++) {
               if (voxels[x][y][z] != null) {
                    // mesh update code
               }
          }
     }
}
...


As it stands, that's what I'm using to create the VBO for the object.

While I'm typing this, another question:  how would I go about applying rotations to each object individually?  I know glRotate and glTranslate would work for the entire world or a single object, but I need to be able to move / rotate individual voxel groups, as well as individual voxels within a group.  If I wanted rotating / moving voxels within the group, it seems inefficient to have to go through and re-work the entire mesh of the thing.  So by that logic, I'm assuming I'd need to have the object have multiple groups of voxels?

Again, just brainstorming, putting it out there for any constructive folk who happen along.

EDIT:  On the subject of "subgroups", perhaps have an enum of what types of subgroups there are?

Also, things like:  Would the gun on a turret need to know about what's going on in the casing it's attached to, AND the main body of a ship?  Or would it just need to know the turret only, since the turret would already compensate for knowing the main body?  Is that kind of "inheritance" going to cause issues?  If so, is there another method around this?  (I'm thinking mainly rotation along this path; the main hull would have its rotation, the turret casing would have its rotation relevant to the hull, and the weapons on the turret would have its rotation relevant to the casing, which is relevant to the hull.)

And on the same topic, what about collisions within the same structure?  What if the turret gun knows about the casing, but not about the main ship?  It would collide / be restricted to the casing, but how would it know to collide with or interact with the main hull?  Is it possible to create a system that does all the collision checking and (possibly) queuing for them?  How would it work?  Raycasting?  Or perhaps another method.
30  Game Development / Game Play & Game Design / Re: Data structure for voxels? on: 2013-07-11 22:20:07
But that array again is larger than what's necessary.  Maybe the memory isn't a big issue, but the extra space still has to be looped through.  Wouldn't that affect the cpu load required rather significantly?
Pages: [1] 2
 
DesertCoockie (54 views)
2018-05-13 18:23:11

nelsongames (86 views)
2018-04-24 18:15:36

nelsongames (76 views)
2018-04-24 18:14:32

ivj94 (761 views)
2018-03-24 14:47:39

ivj94 (93 views)
2018-03-24 14:46:31

ivj94 (645 views)
2018-03-24 14:43:53

Solater (104 views)
2018-03-17 05:04:08

nelsongames (187 views)
2018-03-05 17:56:34

Gornova (428 views)
2018-03-02 22:15:33

buddyBro (1088 views)
2018-02-28 16:59:18
Java Gaming Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39

Java Gaming Resources
by philfrei
2017-12-05 19:36:10

Java Gaming Resources
by philfrei
2017-12-05 19:33:10

List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!