Java-Gaming.org Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (799)
Games in Android Showcase (237)
games submitted by our members
Games in WIP (865)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: 1 [2]
  ignore  |  Print  
  Frame-Rate Independent Tickrate  (Read 10819 times)
0 Members and 1 Guest are viewing this topic.
Offline Grunnt

JGO Kernel


Medals: 143
Projects: 8
Exp: 5 years


Complex != complicated


« Reply #30 - Posted 2014-09-21 08:43:04 »

If you have a logic thread and a render thread, you can save yourself oodles of time.

What problem does your proposed solution solve? Using threading for something like this is generally a Very Bad Idea. In your solution the properties of entities may change while the rendering is performed, potentially leading to graphical glitches (rendering half the entity at one positon, the other half at another) and even worse, crashes (if some data is altered but other not yet leading to invalid state).

Offline radar3301

Junior Newbie





« Reply #31 - Posted 2014-09-21 18:11:06 »

If you have a logic thread and a render thread, you can save yourself oodles of time.

What problem does your proposed solution solve? Using threading for something like this is generally a Very Bad Idea. In your solution the properties of entities may change while the rendering is performed, potentially leading to graphical glitches (rendering half the entity at one positon, the other half at another) and even worse, crashes (if some data is altered but other not yet leading to invalid state).
Include a method in your entities to return the state of the entity at the time the method was called, call that method at the start of performing the render, and store all the returned values from the entities in an array.

If you don't want to create another array for all the entity states, try including a lock/unlock method in the entities, and call those methods at the start/end of the render loop.
Offline Grunnt

JGO Kernel


Medals: 143
Projects: 8
Exp: 5 years


Complex != complicated


« Reply #32 - Posted 2014-09-21 19:11:37 »

Include a method in your entities to return the state of the entity at the time the method was called, call that method at the start of performing the render, and store all the returned values from the entities in an array.

Okay, I can see how that could work with some effort. However, this all sounds needlessly complicated and certainly not a performance gain: deep copying all entities each loop is not free, and rendering speed is mostly done on the GPU anyway.

If you don't want to create another array for all the entity states, try including a lock/unlock method in the entities, and call those methods at the start/end of the render loop.

So the update thread waits for the rendering thread and the rendering thread waits for the update thread. Which turns this into an extremely complicated way to do exactly the same thing as just a single thread performing update and render, or am I missing something here?

Also, neither solution solves the problem posed by the OP: how to make movement independent from framerate.

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline radar3301

Junior Newbie





« Reply #33 - Posted 2014-09-21 23:35:14 »

So the update thread waits for the rendering thread and the rendering thread waits for the update thread. Which turns this into an extremely complicated way to do exactly the same thing as just a single thread performing update and render, or am I missing something here?
Well, I was thinking something more along the lines of
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
class Entity {
    float x, y;
    float lockedX, lockedY;
    void lock() {
        lockedX = x; lockedY = y;
    }

    void render() {
        GraphicsObject.drawWhatever(lockedX, lockedY);
    }
}

class RenderThread {
    void render() {
        for (Entity e : entities)
            e.lock(); // lock the entity
        for (Entity e : entities)
            e.render(); // render the entity
    }
}

I hope that's understandable. Looking at it now, I suppose it's a rather unwieldy with the multiple for loops, but the locking code shouldn't take too long, and while rendering is happening, updates to the entity's position can still occur without glitching the graphics.

Also, neither solution solves the problem posed by the OP: how to make movement independent from framerate.
Another thought I just had...

I was once trying to build a (somewhat accurate) physics simulator for projectiles/particles, but I was getting frustrated since the framerate dropped when I was rendering a lot of them. After thinking about it for a while, I decided upon this solution (forgive me if I didn't fully expand the threads properly, this was just a quick 10 minutes) :
http://pastebin.java-gaming.org/efa701a8c0714
Offline BurntPizza

« JGO Bitwise Duke »


Medals: 486
Exp: 7 years



« Reply #34 - Posted 2014-09-21 23:40:28 »

That's literally just a (messily done) deep copy.
It's still not thread safe at all.
Offline radar3301

Junior Newbie





« Reply #35 - Posted 2014-09-22 05:00:31 »

That's literally just a (messily done) deep copy.
It's still not thread safe at all.
To which snippet are you talking about?
Pages: 1 [2]
  ignore  |  Print  
 
 

 
Riven (201 views)
2019-09-04 15:33:17

hadezbladez (4922 views)
2018-11-16 13:46:03

hadezbladez (1815 views)
2018-11-16 13:41:33

hadezbladez (5196 views)
2018-11-16 13:35:35

hadezbladez (1025 views)
2018-11-16 13:32:03

EgonOlsen (4397 views)
2018-06-10 19:43:48

EgonOlsen (5230 views)
2018-06-10 19:43:44

EgonOlsen (2973 views)
2018-06-10 19:43:20

DesertCoockie (3876 views)
2018-05-13 18:23:11

nelsongames (4308 views)
2018-04-24 18:15:36
Java Gaming Resources
by philfrei
2019-05-14 16:15:13

Deployment and Packaging
by philfrei
2019-05-08 15:15:36

Deployment and Packaging
by philfrei
2019-05-08 15:13:34

Deployment and Packaging
by philfrei
2019-02-17 20:25:53

Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08

Deployment and Packaging
by gouessej
2018-08-22 08:03:45
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!