Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (480)
Games in Android Showcase (110)
games submitted by our members
Games in WIP (546)
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 1292 times)
0 Members and 1 Guest are viewing this topic.
Offline Orangy Tang

JGO Kernel


Medals: 56
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?

[ TriangularPixels.com - 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 public....at least that's the way i'm doing it in these cases.

Offline Orangy Tang

JGO Kernel


Medals: 56
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.

[ TriangularPixels.com - 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 Member




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 Kernel


Medals: 361
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:

1  
2  
3  
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.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

atombrot (20 views)
2014-08-19 09:29:53

Tekkerue (21 views)
2014-08-16 06:45:27

Tekkerue (21 views)
2014-08-16 06:22:17

Tekkerue (12 views)
2014-08-16 06:20:21

Tekkerue (19 views)
2014-08-16 06:12:11

Rayexar (55 views)
2014-08-11 02:49:23

BurntPizza (37 views)
2014-08-09 21:09:32

BurntPizza (28 views)
2014-08-08 02:01:56

Norakomi (35 views)
2014-08-06 19:49:38

BurntPizza (65 views)
2014-08-03 02:57:17
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
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!