Java-Gaming.org Hi !
Featured games (84)
games approved by the League of Dukes
Games in Showcase (603)
Games in Android Showcase (171)
games submitted by our members
Games in WIP (651)
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 3 ... 74
1  Discussions / Miscellaneous Topics / Re: What I did today on: 2015-07-31 02:37:07
Nice, reminds me of this, but for meshes: http://www.snakehillgames.com/spritelamp/
2  Game Development / Newbie & Debugging Questions / Re: Check to see if Triangle intersects Rectangle on: 2015-07-31 02:07:53
@OP: to flesh out my answer:

This SO thread has theory and code for treating the triangle as 3 line segments against a AABB: http://stackoverflow.com/questions/99353/how-to-test-if-a-line-segment-intersects-an-axis-aligned-rectange-in-2d

If speed turns out to be an issue with that method and triangles are often well outside of the rectangle, then computing and testing against the triangle's own AABB might be a fast way to confirm negatives before doing the full line-line-line-rect test, esp. if the triangles coordinates are stored in a way that makes computing the AABB easy.
3  Game Development / Newbie & Debugging Questions / Re: Check to see if Triangle intersects Rectangle on: 2015-07-30 06:24:32
https://www.google.com/search?q=rectangle+triangle+intersection+test

One option is to test each line in the triangle against the rectangle, perhaps first testing the triangle's bounding box against the rectangle.
4  Game Development / Newbie & Debugging Questions / Re: My map load parser is taking ages on android on: 2015-07-29 19:40:46
http://docs.oracle.com/javase/7/docs/api/java/lang/String.html

1  
2  
string.getBytes();
new String(byte[] bytes);
5  Game Development / Newbie & Debugging Questions / Re: Questions about scaling -- libgdx on: 2015-07-28 00:58:17
Well if you don't have to run something on the client, then don't, but in some cases you want to, such as games with real time feedback from other players, in that case the game potentially plays very poorly in less than perfect network conditions. (e.g. what would happen if a FPS game only relied on the server for player and bullet positions? It would totally break in the face of even slight lag without client-side prediction)

Some reading: http://gafferongames.com/networking-for-game-programmers/what-every-programmer-needs-to-know-about-game-networking/
The rest of his articles are worth reading as well.
6  Game Development / Newbie & Debugging Questions / Re: Questions about scaling -- libgdx on: 2015-07-27 20:14:24
Usually (at least for fast-action games that demand low latency) both the client and server run the simulation, with the server providing verification and any necessary correction in player positions etc. if clients are getting out of sync. The correction is what's happening when you see 'rubber banding' in games.
7  Game Development / Newbie & Debugging Questions / Re: How do you handle lots of entities with no lag? on: 2015-07-26 21:39:56
Unless the entities are stored spatially, such as in a grid. Then you only have to check cells that will be on screen. The same can be done for the tiles as well, since they are spacial, as chris said here and ags elaborated on: http://www.java-gaming.org/topics/2d-minecraft-like-game-rendering-issue/36416/msg/345426/view.html#msg345426
8  Game Development / Game Mechanics / Re: Electric network in a tile based game on: 2015-07-26 01:15:46
Quote
A wire merely connects some set of blocks together

'Connects' being in active voice, yes. They are used to connect more important pieces together (or break them apart), otherwise they do nothing, the producer and consumer nodes don't even have to know about them, if you use reference counting in the adjacency lists to implement breaking things apart.

Some code:

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  
class Ref<A> {
    A data;
    int count;
    boolean equals(Ref<A> r) = (data.equals(r.data) && r.count == count); // some pseudojava
}

interface Node {
    boolean isMajor(); // such as a producer/consumer block, wires are minor
    boolean isMinor(); // ...
    Set<Ref<Node>> getAdjacents(); // might not be the best way, could have a set<Node> and a map<Node, Integer> for counts, etc.
    void addAdjacents(Collection<Node> c); // maintains some invariants like 'don't add self', also increments ref counts
    void removeAdjacents(Collection<Node> c); // decrements ref counts, doesn't actually remove things until their count == 0, etc.

    // might actually have to be an abstract class, or static methods or something
    onPlace() {
        addAdjacents(getNodesOnAdjacentMapTiles()); // make sure to increment ref counts
        // branch out from adj nodes, stopping on and collecting nodes that satisfy the predicate
        List<Node> majorConnectedNodes = traverse(getAdjacents(), Node::isMajor);
        majorConnectedNodes.foreach(n -> n.addAdjacents(majorConnectedNodes)); // remember, will automatically filter out self
    }
    onBreak() {
        List<Node> majorConnectedNodes = traverse(getAdjacents(), Node::isMajor);
        majorConnectedNodes.foreach(n -> n.removeAdjacents(majorConnectedNodes));
        // filter out majors because we don't want to double-remove ourselves
        getAdjacents().filter(Node::isMinor).foreach(wire -> wire.removeAdjacents(this)); // single-arg remove could be nice
    }
}

class WireNode implements Node {
/// make sure to call super.onPlace(), etc. is Node is actually an abstract class
}
class RedstoneFurnaceNode implements Node {
/// used by RestoneFurnaceBlock to do things like consume power from adjacents, etc.
}


Probably some more subtleties in there, but that's the rough sketch.
EDIT: such as, major node classes should override onPlace/Break so as not to act as wires (unless they should...), or those impls of mine should just be in the WireBlock/Node class.

EDIT2: after some thought, a more robust albeit perhaps more expensive timewise option would be to have onPlace/onBreak for minor nodes simply find connected major nodes and tell them to recalculate their own major connected nodes. This is preferable because onPlace/Break is unified for minor nodes, and ref counting isn't required. It does require more graph traversals though.
9  Game Development / Game Mechanics / Re: Electric network in a tile based game on: 2015-07-26 00:31:33
Instead of a separate cache (equivalent to an adjacency matrix?), every time the graph is updated, the the traversal is done and then the graph can be reduced:


A-■-■-■-■-■-B-■-■-■-D
      |
      ■ <- just added
      |
      ■
      |
      C


Traversal outward from the updated point (DFS or BFS) finds A, B, and C, so they are all connected, and added to each other's adjacency lists and can directly reference each other. Make sure to use a Set for the adjacencies or otherwise not allow duplicates. Might also include tags for "wire resistance/power capacity" so power limiting can be implemented.
The blocks connecting them still have references, but only to inform ABCD etc. when the graph is changed.
So there's really two separate graphs: the 'wires' and the producers/consumers.
The wires graph is large but only has to be traversed when changes are made, the heavily used producer/consumer graph is much smaller.
10  Game Development / Game Mechanics / Re: Electric network in a tile based game on: 2015-07-25 23:43:52
You only need one queue, just add discovered neighbors (that aren't already marked) in with the rest.
11  Game Development / Performance Tuning / Re: Optimizing Conway's Game of Life on: 2015-07-24 22:07:07
My new version: http://pastebin.java-gaming.org/9cd9369173b16 EDIT: corrected a slice bounds bug in parallelUpdate

At the bottom you can change the update method used in cycle() to see speeds, and in main() you can select either benchmark mode or display.


For serial and parallel update, it uses a sliding-window shift register technique (adapted from here) so as to only do a minimal number of reads. It also uses plenty of loop peeling so as to eliminate the wrapping computation which otherwise has to be done everywhere, as in naiveUpdate().
Even so, serialUpdate() is not much faster than the improved version of yours, fortunately this version is very amendable to parallelization.

The next step from here without moving to the GPU would be only storing and updating cells that have changed, etc. and then onto hashing spacial and temporal redundancies a-la hashlife.
12  Game Development / Performance Tuning / Re: Optimizing Conway's Game of Life on: 2015-07-24 07:01:57
Best I have: it seems removing the if(value != 0) allows removal of zeroing as well.
Reaches the same fixpoint in my random board test at least, so it appears valid, and is about 1.75x faster than with fill().

I'm done for the night, but I'll leave this: http://cell-auto.com/optimisation/
EDIT: also this, specific to Conway's: http://stackoverflow.com/questions/40485/optimizing-conways-game-of-life
13  Game Development / Performance Tuning / Re: Optimizing Conway's Game of Life on: 2015-07-24 06:45:28
I figured it out too, but fill() slows it down a good bit, trying to find a better way.

What about that memory usage though? Can't go around churning >1Gb heaps for no reason.  Pointing
14  Game Development / Performance Tuning / Re: Optimizing Conway's Game of Life on: 2015-07-24 06:18:24
Mmm? Why doesn't it work? Is the interchange in set() not valid?
Let me investigate...
15  Game Development / Performance Tuning / Re: Optimizing Conway's Game of Life on: 2015-07-24 06:06:59
Lol I was writing my findings: 7x faster, 190x less memory usage  Pointing
I knew there was no way the buffer swap was slower...

Note I didn't ever render anything or check validity, but here's the code I wound up with if you're curious: http://pastebin.java-gaming.org/d79cd49133917
16  Game Development / Performance Tuning / Re: Optimizing Conway's Game of Life on: 2015-07-24 05:25:57
But that's the weird part: there's almost no work involved to keep a 2-pool.
Frequent alloc/gc for large chunks of memory (+ zeroing unless your OS keeps pre-zeroed pages, although those will run out) should be much more work.

I can only guess that some optimization analysis (like alias analysis) doesn't like the buffer swap.
Does the cpu profile change much?
17  Game Development / Performance Tuning / Re: Optimizing Conway's Game of Life on: 2015-07-24 05:10:24
Forgot about this:
It's not semantically equivalent until the grid is getting zeroed somewhere in the process.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
public void cycle() {
    byte[] grid = useGridB ? this.gridB : this.gridA;
    byte[] newGrid = useGridB ? this.gridA : this.gridB;
    this.useGridB = !this.useGridB;
+    Arrays.fill(newGrid, (byte) 0); // to make up for not having a freshly allocated (and thus zeroed) array

    for (int j = 0; j < this.height; j++) {
        for (int i = 0; i < this.width; i++) {
            final int idx = this.encode(i, j);
            final int value = grid[idx];
            if (value != 0) // put this back in place, although it sounds like it isn't very beneficial
                this.set(newGrid, i, j, LOOKUP_TABLE[value]);
        }
    }
}


Alternatively newGrid[idx] = 0; in each loop iteration, access patterns between the two arrays might outweigh the vectorizability of fill().
18  Game Development / Performance Tuning / Re: Optimizing Conway's Game of Life on: 2015-07-24 05:00:25
If you remove the if(value != 0) from the original code, does it slow down by roughly the same amount?
19  Game Development / Performance Tuning / Re: Optimizing Conway's Game of Life on: 2015-07-24 04:50:40
Yeah, the 2-pool only adds 1-2 conditionals per cycle() after all is said and done.
The (i + 1) % 2 is equivalent to and will probably reduce to the same thing as the flag = !flag.

EDIT: you could still remove the branch by having the two grids in an array themselves: (although I highly doubt saving 1 branch will mean anything...)
1  
2  
3  
4  
5  
byte[][] grids = { gridA, gridB };

...

grid = grids[counter++ & 1];


Swapping global pointers may adversely affect alias analysis, so I would avoid doing that.


The loops in set() could still be interchanged as well.
20  Game Development / Performance Tuning / Re: Optimizing Conway's Game of Life on: 2015-07-24 04:36:05
Profiling is probably the way to go here (optimizing via forum posts is a bit speculative). But, it seems worth mentioning that your new cycle() function has introduced multiple conditionals in the inner loop that weren't there before, which it seems likely could offset any gains from pooling the grids. Since the results of the conditionals are the same each time though, you should just be able to grab references to the grids at the beginning of the function, at which point your inner loop can go back to the way it was previously.

Lifting the conditionals out of the loop is almost certainly done by the jit, but I agree it would make the code clearer.
See: https://en.wikipedia.org/wiki/Loop-invariant_code_motion
21  Game Development / Performance Tuning / Re: Optimizing Conway's Game of Life on: 2015-07-24 04:20:11
Also, I might be derping, but is there any reason you're using the 3rd bit of everything instead of just using 0 = false, any-other-byte (such as 1) = true?
The jit will probably figure it out, but otherwise that's potentially a lot of unnecessary shifting and masking going on, not to mention code obfuscation.

EDIT: yep, late-night derping.
22  Game Development / Performance Tuning / Re: Optimizing Conway's Game of Life on: 2015-07-24 04:12:52
The bool switch will work.
23  Game Development / Performance Tuning / Re: Optimizing Conway's Game of Life on: 2015-07-24 04:02:45
Non-algorithmic improvements:

Interchange the i, j loops so that the y axis is the outer loop.
If you can, don't allocate a new large array each cycle, but reuse an old one. Even though alloc/free is supposed to be fast for short-lived objects, I often get sizable gains from pooling large arrays.
clear() could simply be Arrays.fill(grid, 0);
24  Game Development / Newbie & Debugging Questions / Re: Best Practices for Creating New Objects on: 2015-07-22 19:16:46
Derp, you're very right. Edited.
25  Game Development / Newbie & Debugging Questions / Re: Best Practices for Creating New Objects on: 2015-07-22 19:06:26
I still get the two loops in -O1 on https://gcc.godbolt.org/, but -O2 cleans it all up.

Since I like thinking about these things, here's a possible transformation path (how 'clever' is it?):

Loop fusion:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
static int test(int n) {
  int ret = 0;
-  for(int i = 0; i < n; i++) {
-    ret++;
-  }
  for(int i = 0; i < n; i++) {
    ret++;
+   ret++;
  }
  return ret;
}


This will get picked up by SCCP if not other passes:

1  
2  
3  
4  
5  
6  
7  
8  
9  
static int test(int n) {
  int ret = 0;
  for(int i = 0; i < n; i++) {
-   ret++;
-   ret++;
+   ret += 2;
  }
  return ret;
}


Induction variable substitution:

1  
2  
3  
4  
5  
6  
7  
8  
static int test(int n) {
  int ret = 0;
  for(int i = 0; i < n; i++) {
-   ret += 2;
+   ret = 2 * (i + 1);
  }
  return ret;
}


Dead store elimination:

1  
2  
3  
4  
5  
6  
7  
8  
static int test(int n) {
-  int ret = 0;
-  for(int i = 0; i < n; i++) {
-   ret = 2 * (i + 1);
-  }
-  return ret;
+  return n >= 0 ? 2 * n : 0;
}


Strength reduction:

1  
2  
3  
4  
static int test(int n) {
-  return n >= 0 ? 2 * n : 0;
+  return n >= 0 ? n + n : 0;
}


Inlined into main: (this would actually probably be first thing that happens, but w/e)

1  
2  
3  
4  
int main(int argc, char** argv) {
-  return test(argc);
+  return argc >= 0 ? argc + argc : 0;
}


And then instruction selection comes up with this:

1  
2  
3  
4  
5  
6  
main:
    lea     eax, [rdi+rdi]
    test    edi, edi
    mov     edx, 0
    cmovle  eax, edx
    ret


LEA is chosen possibly because, unlike ADD, the destination register can be anything, not just the left operand.



Oh, yeah and don't do object pools for small objects, unless testing shows real improvement, etc etc...  persecutioncomplex
26  Game Development / Newbie & Debugging Questions / Re: [libgdx] Allowing sprites to "bypass" lighting on: 2015-07-17 22:52:09
You could also use the depth test or stencil buffer so that the light buffer doesn't get rendered in places where you didn't want it.
27  Game Development / Newbie & Debugging Questions / Re: [libgdx] Allowing sprites to "bypass" lighting on: 2015-07-17 22:30:06
  • Render world buffer minus bypassing sprites
  • Render light buffer on top
  • Render bypassing sprites on top

I'm guessing that the Minecraft examples are actually due to per-vertex info or similar though. Is your system 2D or 3D?
28  Java Game APIs & Engines / Engines, Libraries and Tools / Re: Java OpenGL Math Library (JOML) on: 2015-07-14 22:15:12
I'm working on making the jitted 'matrix construction templates' (as I call them) work for transforming FloatBuffers containing many matrices at once. Would that be a relevant use case @theagentd? That's what I got out of your prior example with queues and seems like a use that would actually benefit from this tech. (1 JNI call to transform N matrices per unique op sequence)
29  Java Game APIs & Engines / Engines, Libraries and Tools / Re: Java OpenGL Math Library (JOML) on: 2015-07-14 21:00:34
Now with the dynamic label jumping (aka threaded code) this is closer to an embedded Forth than ever.
30  Java Game APIs & Engines / Engines, Libraries and Tools / Re: Java OpenGL Math Library (JOML) on: 2015-07-14 16:55:13
Your previous post was a bit confusing to me. If I understood it right, you're saying that I could create a small native function by giving JOML an opcode buffer which is then somehow compiled to a native function? Huh So... Software compute shaders for Java? O_o

It's a jit: https://github.com/JOML-CI/JOML/blob/native-interpreter/native/src/codegen.dasc

The idea is that your regular java code (chains of JOML methods) produce a native function in memory at runtime.

Here's the pure java test case: https://github.com/JOML-CI/JOML/blob/native-interpreter/test/org/joml/NativeMatrix4f.java#L108
In the current impl, the Sequence object is essentially a function pointer to the native function, you set it's arguments and call it.
NativeMatrix is a builder pattern for an opcode buffer that gets compiled to SSE code when you call terminate().
Pages: [1] 2 3 ... 74
 
SHC (11 views)
2015-08-01 03:58:20

Jesse (17 views)
2015-07-29 04:35:27

Riven (38 views)
2015-07-27 16:38:00

Riven (19 views)
2015-07-27 15:35:20

Riven (22 views)
2015-07-27 12:26:13

Riven (12 views)
2015-07-27 12:23:39

BurntPizza (32 views)
2015-07-25 00:14:37

BurntPizza (43 views)
2015-07-24 22:06:39

BurntPizza (25 views)
2015-07-24 06:06:53

NoxInc (31 views)
2015-07-22 22:16:53
List of Learning Resources
by gouessej
2015-07-09 11:29:36

How Do I Expand My Game?
by bashfrog
2015-06-14 11:34:43

List of Learning Resources
by PocketCrafter7
2015-05-31 05:37:30

Intersection Methods
by Roquen
2015-05-29 08:19:33

List of Learning Resources
by SilverTiger
2015-05-05 10:20:32

How to: JGO Wiki
by Mac70
2015-02-17 20:56:16

2D Dynamic Lighting
by ThePixelPony
2015-01-01 20:25:42

How do I start Java Game Development?
by gouessej
2014-12-27 19:41:21
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!