![]() |
|
|
#1 |
![]() Join Date: Feb 2010
Posts: 1,360 (1.12/day)
Thanks: 1,414
Thanked 276 Times in 194 Posts
|
What would be the best ways to communicate this type of data?
I'm trying to make a turn-based game, and I'm trying to figure out how to communicate between the game and the graphics. Something along the lines of:
The real intention is that the game tells the graphics what is going on, and the graphics tells the game what the player wants to do, and I don't exactly know what the best way to go about this is. I was thinking maybe keeping them in seperate processes and using pipes to communicate the actions and chunks of shared memory for the map data and such. I'm working with C in Linux (at the moment).
__________________
"Doom means two things: demons and shotguns." -John Carmack |
|
|
|
|
|
#2 |
![]() Join Date: Jan 2012
Location: Dover, New Hampshire, USA
Posts: 4,505 (8.87/day)
Thanks: 1,441
Thanked 1,423 Times in 1,063 Posts
|
I wouldn't start micro-optimizing quite yet. Stick with your one process and if performance drops you can then think about how to speed it up. How far is your application, what do you have already?
__________________
MyHeat |
|
|
|
|
|
#3 |
![]() Join Date: Feb 2010
Posts: 1,360 (1.12/day)
Thanks: 1,414
Thanked 276 Times in 194 Posts
|
It's to the point where I need to see what I'm doing (AKA I've got the map system, do I'll be starting the menuing system, and while I'm doing that I'll be working with characters), but I do want the graphics and the game to be as seperate as possible so I can get the game working and then just churn out different graphics libraries (nCurses, SDL, SFML, maybe OpenGL) for it.
__________________
"Doom means two things: demons and shotguns." -John Carmack |
|
|
|
|
|
#4 |
![]() Join Date: Feb 2010
Posts: 1,360 (1.12/day)
Thanks: 1,414
Thanked 276 Times in 194 Posts
|
It seems I've just mastered pthread.h if that's any help.
__________________
"Doom means two things: demons and shotguns." -John Carmack |
|
|
|
|
|
#5 | |
![]() Join Date: Jul 2011
Location: Kaunas, Lithuania
Posts: 568 (0.82/day)
Thanks: 433
Thanked 269 Times in 156 Posts
|
Quote:
While the graphics just draw what the engine tells it to. And informs the engine it finished some marked animation sequence (e.g. a square-to-square walking animation that is marked, so the graphics inform when it finished this sequence, while the engine waits for the graphics to do so while doing other tasks. When the engine receives "I finished this walking thing" it already knows what it asked the graphics to do and continues from there, along with knowing it is now safe to issue other "major" commands to the graphics) In other words: the game engine tracks things while the graphics are "dumb" and just do what told to do and only inform when it finishes things so the game engine can sync with it. At least that's the structure I imagine.
__________________
Why do you wear glasses if you're deaf? Code:
while (1) {
alone();
}
|
|
|
|
|
|
|
#6 |
![]() Join Date: Feb 2010
Posts: 1,360 (1.12/day)
Thanks: 1,414
Thanked 276 Times in 194 Posts
|
That's not quite what I'm asking.
__________________
"Doom means two things: demons and shotguns." -John Carmack |
|
|
|
|
|
#7 |
|
Hardcore Monkey Moderator
Join Date: Feb 2007
Location: Cheeseland (Wisconsin, USA)
Posts: 12,254 (5.27/day)
Thanks: 591
Thanked 5,510 Times in 2,948 Posts
|
The graphics don't tell the game anything. The game simply displays the graphics.
Everything is done in the game code, and then displays the graphic results.
__________________
Cloud (noun, singular): A dynamic arrangement of multiple potential single points of failure, with a user at one end and their data at the other. Get more tech news on a wide variety of topics at NextPowerUp
|
|
|
|
|
|
#8 |
![]() Join Date: Jul 2011
Location: Kaunas, Lithuania
Posts: 568 (0.82/day)
Thanks: 433
Thanked 269 Times in 156 Posts
|
I know.
The thing is, the way You put it, the system would be so overly complicated I don't think it would be feasible, let alone efficient. Thus, unless You describe/show us something of what You already have and describe what You still need to do in better detail, I'm afraid there's very little help we can provide. IOW: "Help us help You"
__________________
Why do you wear glasses if you're deaf? Code:
while (1) {
alone();
}
|
|
|
|
|
|
#9 |
![]() Join Date: Feb 2010
Posts: 1,360 (1.12/day)
Thanks: 1,414
Thanked 276 Times in 194 Posts
|
How is the game supposed to know what the player wants to do? The graphics would have to handle what the player is clicking on, selecting, etc. since the game won't be able to tell what the mouse is over.
__________________
"Doom means two things: demons and shotguns." -John Carmack |
|
|
|
|
|
#10 | |
![]() Join Date: Jul 2011
Location: Kaunas, Lithuania
Posts: 568 (0.82/day)
Thanks: 433
Thanked 269 Times in 156 Posts
|
Quote:
The game engine tracks where everything is. And the game engine receives human input. And then things like this come into play [indirect hint] Hitbox. Really, graphics just draw. And maybe informs the engine when it finishes doing things.
__________________
Why do you wear glasses if you're deaf? Code:
while (1) {
alone();
}
|
|
|
|
|
|
|
#11 |
![]() Join Date: Feb 2010
Posts: 1,360 (1.12/day)
Thanks: 1,414
Thanked 276 Times in 194 Posts
|
How is the game supposed to know what the mouse is over if the graphics draw it?
....I'll put it this way, here's is what the game outputs (to the screen) in the middle of a battle: Code:
__________________
"Doom means two things: demons and shotguns." -John Carmack |
|
|
|
|
|
#12 |
![]() Join Date: Mar 2009
Posts: 490 (0.32/day)
Thanks: 0
Thanked 171 Times in 158 Posts
|
Picture this:
Any character/object in the game has a set of polygons (or equation for ray-marching) that makes it up (visually/physically), a position in space (X, Y, Z) and a orientation (looking at). When the player presses the WASD keys it changes the players character X,Y,Z position, when the player moves the mouse it changes the Yaw,Pitch,Roll orientation. Now if you cast an ray starting at the player character position with the same orientation has the player character and intersect that ray with all the polygons that make the objects displayed on the screen and then select the first one (actually you should z-sorting before hit-test, and also use hit-boxes like spheres or later on cuboids for each object as an optimization) you get the object the player is looking at. Take a look at some, very simple yet very good, NeHe OpenGL tutorials to get a glimpse of what you gotta do. And yet, game engines track everything, and a lot more that what is visually drawn on the screen. Good luck. Last edited by temp02; Oct 25, 2012 at 08:14 PM. Reason: added a link about simple ray-plane/polygon intersection |
|
|
|
|
|
#13 |
![]() Join Date: Jul 2011
Location: Kaunas, Lithuania
Posts: 568 (0.82/day)
Thanks: 433
Thanked 269 Times in 156 Posts
|
That depends on how You handle the input. And on many, many other things.
But really, it's hard to suggest anything solid till we know more about Your engine. One suggestion that might be gold for one WIP game, could be a "red herring" for another...
__________________
Why do you wear glasses if you're deaf? Code:
while (1) {
alone();
}
|
|
|
|
|
|
#14 | ||
![]() Join Date: Feb 2010
Posts: 1,360 (1.12/day)
Thanks: 1,414
Thanked 276 Times in 194 Posts
|
Quote:
Quote:
The game is responsible for:
The graphics are responsible for:
So let's go through a turn of battle:
__________________
"Doom means two things: demons and shotguns." -John Carmack |
||
|
|
|
|
|
#15 |
![]() Join Date: Mar 2009
Posts: 490 (0.32/day)
Thanks: 0
Thanked 171 Times in 158 Posts
|
The same basic logic/math still applies, you just ditch one of the coordinates.
Also you seem to be joining both game output (display) and user input. Both should be separated "components". Parsing user input should be just a layer on top of the already coded game actions for lets say a bot, the same applies for the game output. bot: Code:
move to this tile; no can do; bot selects another tile; move there then; ok, bot moved; Code:
player clicks on x,y; translate coordinate to tile; move to this tile; no can do; print "stupid" on screen; player selects another tile; player clicks on x,y; translate coordinate to tile; move here instead then; ok, player moved; print "you moved"; What would happen if you decided to introduce a framework like SLD into the mix to replace your "graphics" core, would you need to change the interface of the game core? (you shouldn't have too) Now, if you are referring to IPC for passing information between game/engine components my advice would be to use none (except for critical sections and synchronization ofc). It would require you to create a protocol, and all the extra code would introduce no improvement (except for Sockets that if used properly could make your game playable on a remote client, just like X11). Just make your engine run at a certain rate, the user input should make "hard calls" to a input queuing system that is visited on each iteration by the core, and the visual/audio part of the game should just "ask" the core what to render as fast as it can and nothing more (apart from storing animation time/frame ofc). Last edited by temp02; Oct 26, 2012 at 02:35 AM. |
|
|
|
|
|
#16 |
![]() |
Somebody else working on a turn-based hexagonal grid RPG? Oh snap!
At its heart, it's really just the game portion. It could be contained entirely as a text based game like many earlier PC games. The graphics is just a user interface and embellishment. What you're trying to think of as "Managing user input (the player clicked on this button, etc.) and telling the game what action the player is trying to do" is mostly a "GetCursorPosition()" call and comparing the results with other visual elements (both the menus and the game world).
You'll notice I've done checks earlier to make the menu more informative and less redundant checking. Also, from what you've described, it seems a bit like Elven Legacy and/or Fantasy Wars (due to the whole sight thing) combined with an character queue-based SRPG (Sacred Blaze, Wind Fantasy 6, Phantom Brave, Final Fantasy Tactics, etc.). The other thing is to tell the game to wait while the graphics are doing their thing. For example, waiting until the walking is completed before bringing up the action menu again. You could have a fancy cursor following the mouse pointer. But then again, if you can get that working, the rest of this should a breeze. EDIT:temp02 got it. You're trying to combine the game logic with the graphics display. Do the game logic first. The graphics is just for user (player) convenience. It should reflect that by simply embellishing game actions. Last edited by SaltyFish; Oct 26, 2012 at 02:11 AM. |
|
|
|
|
|
#17 | |||||
![]() Join Date: Feb 2010
Posts: 1,360 (1.12/day)
Thanks: 1,414
Thanked 276 Times in 194 Posts
|
Quote:
Quote:
Quote:
Quote:
Quote:
I guess maybe I could just write a simple terminal thing to tell me what the game would tell the graphics, and then just write back what the graphics would have told the game or something.
__________________
"Doom means two things: demons and shotguns." -John Carmack |
|||||
|
|
|
|
|
#18 | |
![]() Join Date: Jan 2012
Location: Dover, New Hampshire, USA
Posts: 4,505 (8.87/day)
Thanks: 1,441
Thanked 1,423 Times in 1,063 Posts
|
Some things don't need to be abstracted. I think I understand what you're trying to get at. Graphics don't need to be abstract because once you choose a graphics library to handle all of your 3d rendering, it's extremely unlikely that you will need to support a second plug-able renderer.
I think we need to be perfectly clear about one thing: The game computes everything, not the renderer. The graphics are strictly OUTPUT. The game creates the information that tells the graphics what to put out to the screen. So you look for the user input inside the game and when it comes you have the game update the graphics to change what the user sees, the graphics doesn't work independent of the game. The graphics doesn't handle input or entities as complex as your describing. When anything "happens" in the game, it's not the graphics processing it. So tell me one thing. If the graphics/render handles the input, how the heck is the game going to know about it? ![]() Quote:
__________________
MyHeat |
|
|
|
|
| The Following User Says Thank You to Aquinus For This Useful Post: |
|
|
#19 |
![]() Join Date: Jul 2011
Location: Kaunas, Lithuania
Posts: 568 (0.82/day)
Thanks: 433
Thanked 269 Times in 156 Posts
|
Yet again, the engine should keep track of everything it needs to run correctly. You should heed Aquinus' advice. What He tells The Good Stuff™.
And to illustrate a little better, to what degree the engine should handle&track things: Imagine all the graphics/drawing functions are stubs. The engine should still be able to track and handle enough things, that playing such a "blind" game would be possible - everything's running correctly and the engine handles the input on the [empty] game screen according to where the things should be it they were drawn.
__________________
Why do you wear glasses if you're deaf? Code:
while (1) {
alone();
}
|
|
|
|
| The Following User Says Thank You to Vinska For This Useful Post: |
|
|
#20 | ||||||
![]() Join Date: Feb 2010
Posts: 1,360 (1.12/day)
Thanks: 1,414
Thanked 276 Times in 194 Posts
|
Quote:
Quote:
Quote:
Quote:
Quote:
Quote:
Where things are (or should be) drawn is none of the game's concern. The game does gameplay and where a menu is on the screen is not gameplay. Where a character or menu or something is drawn on the screen is purely interface-related information, and graphics is the interface. Therefor the graphics keeps track of menus and where things are drawn.
__________________
"Doom means two things: demons and shotguns." -John Carmack |
||||||
|
|
|
|
|
#21 |
![]() Join Date: Jul 2011
Location: Kaunas, Lithuania
Posts: 568 (0.82/day)
Thanks: 433
Thanked 269 Times in 156 Posts
|
This is how You describe what You need:
Spoiler
And this is the sane way to do it (highly simplified and many things not shown) : Spoiler
Seriously, man, graphics only draw things, just get over and deal with it. P.S. I am not sure if I put everything correctly in these graphs, but You should get the idea.
__________________
Why do you wear glasses if you're deaf? Code:
while (1) {
alone();
}
|
|
|
|
|
|
#22 |
![]() Join Date: Feb 2010
Posts: 1,360 (1.12/day)
Thanks: 1,414
Thanked 276 Times in 194 Posts
|
Honestly, I like the first one better.
__________________
"Doom means two things: demons and shotguns." -John Carmack |
|
|
|
|
|
#23 |
![]() Join Date: Jul 2011
Location: Kaunas, Lithuania
Posts: 568 (0.82/day)
Thanks: 433
Thanked 269 Times in 156 Posts
|
Yeah, it does look much more simple
'cept that it isn't and it probably won't work! FWIW, it is technically possible. But it would be extremely complicated. And I also suspect You would have such a bad performance [methaphor]it would get on a train and ride all the way to the land of "so bad, it's funny.". But would not stop there and go further and then enter into the land of "so bad, it's simply sad."[/methaphor] You would either have to do most of Your graphics on the CPU, or have ridiculously large amount of crosstalk between the GPU and the CPU, along with introducing MANY stalls in the GPU, and introducing a lot of points for silly bottlenecks. Did I mention it would be extremely complicated. I wouldn't be surprised if You have to somehow route a lot of graphics functions as GPGPU functions just to be able to supply the required data to the CPU. IOW: Don't reinvent the wheel.
__________________
Why do you wear glasses if you're deaf? Code:
while (1) {
alone();
}
|
|
|
|
|
|
#24 |
![]() Join Date: Feb 2010
Posts: 1,360 (1.12/day)
Thanks: 1,414
Thanked 276 Times in 194 Posts
|
How so? A thread for the interfaces (mouse, keyboard, menus, windows, etc.) and a thread for rendering under the graphics process should be perfect, the two threads could talk to each other incredibly fast because they're both in the same process and the two processes (game and graphics) don't need to talk all that incredibly fast to each other through the pipes because communication between them is few and far between, and any large data can stored in shared memory (the game could tell the graphics what the shmid is through the pipes, and the graphics would be responsible for the memory chunk).
It's perfect.
__________________
"Doom means two things: demons and shotguns." -John Carmack |
|
|
|
|
|
#25 |
![]() Join Date: Jul 2011
Location: Kaunas, Lithuania
Posts: 568 (0.82/day)
Thanks: 433
Thanked 269 Times in 156 Posts
|
Spoiler
You know what? From what You are telling, You seem to know well enough of what Your game needs. We are no longer needed. Just go and finish Your game... ...When You do, sharing the results would be swell!
__________________
Why do you wear glasses if you're deaf? Code:
while (1) {
alone();
}
|
|
|
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| what would be the cause of this... | Darkgundam111 | General Hardware | 1 | Jun 12, 2009 01:01 AM |
| What type of dvd player would work best for a tv that is already a widescreen? | drfksautjio | Overclocking & Cooling | 1 | Nov 11, 2008 05:50 AM |
| What is the best 4870 brand/type available? | LoWRiDeR82 | AMD / ATI | 8 | Jul 12, 2008 11:49 AM |
| what would be the best upgrade(s) | p_o_s_pc | General Hardware | 61 | Aug 24, 2007 10:13 PM |
| What would be the best heatsink? | p_o_s_pc | Overclocking & Cooling | 39 | Jul 27, 2007 12:45 AM |