Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (739)
Games in Android Showcase (224)
games submitted by our members
Games in WIP (820)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Swappable renderer without C++ 'friend'  (Read 2195 times)
0 Members and 1 Guest are viewing this topic.
Offline Orangy Tang

JGO Kernel

Medals: 57
Projects: 11

Monkey for a head

« Posted 2003-04-26 11:44:48 »

If this was C++, i'd be happily using the 'friend' keyword, as is i'm stuck as to how to do this..

So theres a 'World' class which holds the game state, character position etc. etc. and has all the game logic in it. Along with this we have a GLRenderer and a J2DRenderer, each rendering the world in its own way. Thus any generic info goes in World, anything drawing related (textures, sprites etc.) goes in the appropriate renderer.

Problem is the actual rendering code - each renderer obviously needs access to the World data, and not in an abstracted way, but in a raw data sense. This means that the two become tightly coupled, but this is unavoidable. But without a friend, the only solution is to make the World data public (ick, ugly and dangerous), add a whole bunch of getters (not much of an improvement really) or...?

Anyone any ideas?

[ - Play Growth Spurt, Rescue Squad and Snowman Village ] [ Rebirth - game resource library ]
Offline EgonOlsen
« Reply #1 - Posted 2003-04-26 11:55:11 »

...put it in the same package and make it package public only? Not that nice too, but better than completely least that's the way i'm doing it in these cases.

Offline Orangy Tang

JGO Kernel

Medals: 57
Projects: 11

Monkey for a head

« Reply #2 - Posted 2003-04-26 12:59:35 »

Sorry, I should of mentioned that I had thought of this, but the classes already reside in much more logical packages. Plus what happens when you get friend cases overlapping?

Unfortunatly this looks like being the best solution though.

[ - Play Growth Spurt, Rescue Squad and Snowman Village ] [ Rebirth - game resource library ]
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Mojomonkey

Senior Devvie

ooh ooh eee eeee

« Reply #3 - Posted 2003-04-26 13:19:12 »

Perhaps create managers for all your shared data? That is, make a TextureManager, EntityManager, etc. These managers are then singletons and can be accessed from anywhere. Then you either don't need the single world class or it can be a wrapper to make population of the managers easier.

Just a thought.

Don't send a man to do a monkey's work.
Offline princec

« JGO Spiffy Duke »

Medals: 952
Projects: 3
Exp: 16 years

Eh? Who? What? ... Me?

« Reply #4 - Posted 2003-04-26 19:46:54 »

You're maybe thinking about it the wrong way. A world should be able to render itself:

class World {
public void render(WorldRenderer renderer) {...}

The WorldRenderer interface will provide the raw interface to rendering operations - "draw this set of sprites", etc.

The implementations of WorldRenderer will take care of translating to the appropriate underlying API.

Cas Smiley

Pages: [1]
  ignore  |  Print  
You cannot reply to this message, because it is very, very old.

Ecumene (52 views)
2017-09-30 02:57:34

theagentd (76 views)
2017-09-26 18:23:31

cybrmynd (184 views)
2017-08-02 12:28:51

cybrmynd (182 views)
2017-08-02 12:19:43

cybrmynd (189 views)
2017-08-02 12:18:09

Sralse (197 views)
2017-07-25 17:13:48

Archive (747 views)
2017-04-27 17:45:51

buddyBro (881 views)
2017-04-05 03:38:00

CopyableCougar4 (1429 views)
2017-03-24 15:39:42

theagentd (1319 views)
2017-03-24 15:32:08
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

SF/X Libraries
by SkyAphid
2017-03-02 06:38:56

SF/X Libraries
by SkyAphid
2017-03-02 06:38:32

SF/X Libraries
by SkyAphid
2017-03-02 06:38:05

SF/X Libraries
by SkyAphid
2017-03-02 06:37:51 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‑
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!