|
Klaim
|
 |
« Reply #15 on: April 23, 2012, 09:08:55 PM » |
|
Too bad you can't do that in C++. Wheut?  Obviously you can. Flynn1179> You basically discovered task-based concurrency. Congratulations!!!  It's useful for a lot of kinds of games (not helpful for all though) and from what I remember a lot of very big game on multithreaded consoles do use something similar. You can get a taste of the state of the art of this by reading the Intel Threading Building Blocks documentation. Their task system is basically the same idea, but assume that you will work with a pool of worker threads, but the generic idea works with single thread too. That being said, I dont consider myself a specialist in the domain so I might be wrong. Anyway, I'm considering using a similar pattern than you's in my current game "loop" (it wouldnt be a loop anymore, just scheduled tasks), but I'm not sure yet if I'll use ITBB or if a simple C++11 threading library based solution would be enough (I doubt it). I plan to test it on both quad and single core.
|
|
|
|
|
Logged
|
|
|
|
|
Eigen
|
 |
« Reply #16 on: April 23, 2012, 09:39:54 PM » |
|
Too bad you can't do that in C++. Wheut?  Uh, how? There most certainly isn't anything built into the language to faciliate it. In Obj-C you can do [self performSelector:@selector(runMyTask) afterDelay:0.5] and stuff like that. I don't mean something like if (mytimer > 0.5) runMyTask() because that's hardly a feature of the language ...
|
|
|
|
|
Logged
|
|
|
|
|
Klaim
|
 |
« Reply #17 on: April 24, 2012, 03:06:29 AM » |
|
Ok, let me restate this, because I am not clear at all on this case and its not obvious to everybody:
Yes, C++ will not do it in the language, that would be ridiculous considering the design of the language that is, to say the least, not focused on event-driven context live Objective-C.
Yes you still can do an equivalent system simply by mixing std::function and std::chrono if you need time related stuff. Yes it's more work but C++ is well known to be a very good language when the purpose is to provide a reusable library, so you can find one or just setup a system that work for you (I did it often, its quick to setup).
Also, boost::asio and boost::timer does allow to do what you say too. Boost asio looks on it s way to the standard library by the way.
But yeah basically C++ cant do it on the language level and its by design. I wonder how they manage multithreading in ObjectiveC with event dispatching... looks like performance hell...
|
|
|
|
|
Logged
|
|
|
|
|
Average Software
|
 |
« Reply #18 on: April 24, 2012, 04:44:02 AM » |
|
Uh, how? There most certainly isn't anything built into the language to faciliate it. In Obj-C you can do [self performSelector:@selector(runMyTask) afterDelay:0.5] and stuff like that.
I don't mean something like if (mytimer > 0.5) runMyTask() because that's hardly a feature of the language ...
What you're doing isn't a feature of Objective-C either. It's a feature of Cocoa. Objective-C as a language provides very little beyond basic message passing. Raw Objective-C doesn't even provide anything beyond malloc/free for object creation and destruction.
|
|
|
|
|
Logged
|
|
|
|
|
rogerlevy
Guest
|
 |
« Reply #19 on: April 24, 2012, 06:25:11 AM » |
|
i just realized that this must be why quantum mechanics exists
the universe can't just know that the bullet hit the storm trooper
it has to do it pixel by pixel
|
|
|
|
|
Logged
|
|
|
|
|
st33d
Guest
|
 |
« Reply #20 on: April 24, 2012, 06:34:51 AM » |
|
That's not quantum mechanics. Quantum mechanics is when you test for collision it's in a different place to when you don't test for collision.
|
|
|
|
|
Logged
|
|
|
|
|
rogerlevy
Guest
|
 |
« Reply #21 on: April 24, 2012, 07:58:04 AM » |
|
Serious question - if you use pixel positions and multiple updates how do you process motion in arbitrary angles and subpixel accurate speeds?
|
|
|
|
|
Logged
|
|
|
|
|
Flynn1179
|
 |
« Reply #22 on: April 24, 2012, 08:17:49 AM » |
|
Arbitrary angles, I wouldn't use pixel positions for- as far as subpixel accurate speeds, it depends what you mean. If you mean something moving at 1/10th of a pixel every second (for example), then you just schedule a move of one pixel every 10 seconds.
|
|
|
|
|
Logged
|
|
|
|
|
rogerlevy
Guest
|
 |
« Reply #23 on: April 24, 2012, 08:36:14 AM » |
|
Arbitrary angles, I wouldn't use pixel positions for- as far as subpixel accurate speeds, it depends what you mean. If you mean something moving at 1/10th of a pixel every second (for example), then you just schedule a move of one pixel every 10 seconds.
gravity, velocity, physics. when you don't know exactly the speed at a given point ahead of time, or it's not an integer fraction.
|
|
|
|
|
Logged
|
|
|
|
|
xrabohrok
|
 |
« Reply #24 on: April 25, 2012, 04:58:55 AM » |
|
Like people have pointed out before, this system would work best when timing isn't such a big deal as this system could exacerbate race conditions, though it wouldn't matter most of the time. The only time I could think it would be noticeable would be with moving land-mines or something.
It's somewhat gotten to the point where C++ can do anything, it just won't be fun programming.
|
|
|
|
|
Logged
|
A picture is worth a 1000 words, so naturally they save a lot of time.
|
|
|
|
Flynn1179
|
 |
« Reply #25 on: April 25, 2012, 05:54:26 AM » |
|
That's odd.. all changes to game objects are handled in precisely the order they should be, it actually prevents a lot of timing issues, including race conditions. What makes you think it would exacerbate them?
|
|
|
|
|
Logged
|
|
|
|
|
KeeWeed
|
 |
« Reply #26 on: April 25, 2012, 06:22:17 AM » |
|
It's an interesting thought! I specially like the timing of things, because I think that is often a bit of a hassle. I mean it's not that hard, but if it would be easy like this, I reckon you'll use it very often and a game can get very smooth. On the other hand, the problem with these timing things is that you'll have to check whether you still want to execute that command after the time has passed. Like the door that closes after 10 secs. What if the player pushed a crate between it. What if player events like firing, dying and hitting the door for the next level are executed right after each other? I'm not saying it's impossible, but with the traditional update method, the developer simply has more control over the executing order.
Also, I do see a problem with 'updating objects 1 pixel at a time'. A game space shouldn't be defined by the way it gets drawn on the screen, that is in pixels. Coordinates should be done in floats, always. Using ints you rule out things like anti-aliasing as well...
|
|
|
|
|
Logged
|
|
|
|
|
Dacke
|
 |
« Reply #27 on: April 25, 2012, 06:27:14 AM » |
|
Also, I do see a problem with 'updating objects 1 pixel at a time'. A game space shouldn't be defined by the way it gets drawn on the screen, that is in pixels. Coordinates should be done in floats, always. Using ints you rule out things like anti-aliasing as well...
I agree that it's generally good to have a model/representation of a world/system that is independent of how it is displayed to the user. But that is not at all the same thing as always using floats for coordinates; many games benefit from clearly quantified coordinates.
|
|
|
|
|
Logged
|
vegan • socialist • atheist • humanist • liberal • FOSSer programmer • feminist • animal rights activist • pacifist • teetotaller
|
|
|
|
KeeWeed
|
 |
« Reply #28 on: April 25, 2012, 06:36:12 AM » |
|
Games like that have a grid-based space. If I would have to make a game like that, I would still take floats and build a coordinate system on top of that to position stuff that needs this kind of grid position. Just using ints on the core of your entire positioning system... well, it feels completely wrong to me. But maybe I'm just not oldskool enough 
|
|
|
|
|
Logged
|
|
|
|
|
Dacke
|
 |
« Reply #29 on: April 25, 2012, 07:01:38 AM » |
|
So if you were to implement Chess, you would use floats in your model of the 'world'? class ChessPiece { float x, y; ...

|
|
|
|
|
Logged
|
vegan • socialist • atheist • humanist • liberal • FOSSer programmer • feminist • animal rights activist • pacifist • teetotaller
|
|
|
|