Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (522)
Games in Android Showcase (127)
games submitted by our members
Games in WIP (590)
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  
  [Don't even look] I think I've found a bug in my brain  (Read 3571 times)
0 Members and 1 Guest are viewing this topic.
Offline jonjava
« Reply #30 - Posted 2011-11-09 13:11:23 »

It is a data structure, and bricks are designed to sit in a grid, forming a landscape. They can only move inside this grid. Think of Minecraft.

... what does this have to do with anything? Every 'map' is a data structure of some kind. Minecraft as an example is horrendous. Sure, you place bricks within a "grid" of sorts, but there's other ways of limiting bricks to 'sit inside a grid'. I haven't directly looked into Minecraft's code but I can't see how it would use your way of representing the bricks. Ie looping through the whole [ x][y][z] plane checking every iteration if there's a brick there, and if there is, look up that bricks specific type, and further now that we know what type it is, ask the resource manager for it's sprite, and only then draw it on the screen.

That's a maximum of 4 actions to draw a brick.

1) Is there a brick at <insert position here>?
2) if yes, check what type of brick it is
3) with type, ask resource manager what sprite to use
4) draw brick.

Instead of something like this:

loop through ArrayList of bricks

1) while (list.hasNext()) list.next().draw(g).

I mean, it's not wrong. Just seems to me you're making it unnecessarily complicated. Feel free to prove me wrong, I just can't see the Pro's in your method - could you clarify?

Offline Mads

JGO Ninja


Medals: 26
Projects: 3
Exp: 6 years


One for all!


« Reply #31 - Posted 2011-11-13 05:47:48 »

It is a data structure, and bricks are designed to sit in a grid, forming a landscape. They can only move inside this grid. Think of Minecraft.

... what does this have to do with anything? Every 'map' is a data structure of some kind. Minecraft as an example is horrendous. Sure, you place bricks within a "grid" of sorts, but there's other ways of limiting bricks to 'sit inside a grid'. I haven't directly looked into Minecraft's code but I can't see how it would use your way of representing the bricks. Ie looping through the whole [ x][y][z] plane checking every iteration if there's a brick there, and if there is, look up that bricks specific type, and further now that we know what type it is, ask the resource manager for it's sprite, and only then draw it on the screen.

That's a maximum of 4 actions to draw a brick.

1) Is there a brick at <insert position here>?
2) if yes, check what type of brick it is
3) with type, ask resource manager what sprite to use
4) draw brick.

Instead of something like this:

loop through ArrayList of bricks

1) while (list.hasNext()) list.next().draw(g).

I mean, it's not wrong. Just seems to me you're making it unnecessarily complicated. Feel free to prove me wrong, I just can't see the Pro's in your method - could you clarify?

You are going to check if there is a brick present, or you will have a nullpointer, the way you just presented it.
If the brick is going to draw itself, it will need what to draw.
Either, it will hold the texture itself. This makes large maps very memory consuming. Asking for the texture however, is using much less memory. In my opinion, having each brick holding its own texture is a waste of memory, if they are all the same anyway. Unless they are all unique, asking is less memory consuming.

You could ofcourse have the brick ask itself. In that case, it would be a matter of opinion of where to put the logic.
Since this is a data object only, I choose not to have logic in it. It just helps my productivity to keep logic in one place. If a player hits a brick, should the brick check if the player has hit it, or should the player check if he has hit a brick? In my case, I can just check if the two collided, and notify them.

Ahh, minecraft. See, I'm presenting my map, in a similar way to minecrafts map. I have a grid, that holds bricks. Each brick is defined by its place in this grid. Not in the world. I can remove it on the index, if the player dug it up.
If I want a brick, that can move around freely, I would create an entity that is placed by world coordinates. It will also need collision detection, and update every tick. This is cpu intensive, if every brick should be able to do that.
Also, if they should be sitting in world cordinates, it would take up a lot more memory, in just basic data types.
Imagine 16000 shorts, turning into ints. Maybe even doubles, for small amounts of speed, that doesnt move a pixel a tick.
Also velocities would need to be defined, also in doubles.

Right now, I can have fairly large maps loaded in memory ready to be used, all the time. I dont need to the extra features, and if I do, Ill make a different entiry for it. Minecraft does this, for instance.
I would rather have less loading time, and a little more challenged coding, than a bad user experience and easy programming. 

Pages: 1 [2]
  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.

trollwarrior1 (33 views)
2014-11-22 12:13:56

xFryIx (73 views)
2014-11-13 12:34:49

digdugdiggy (52 views)
2014-11-12 21:11:50

digdugdiggy (46 views)
2014-11-12 21:10:15

digdugdiggy (40 views)
2014-11-12 21:09:33

kovacsa (65 views)
2014-11-07 19:57:14

TehJavaDev (70 views)
2014-11-03 22:04:50

BurntPizza (68 views)
2014-11-03 18:54:52

moogie (83 views)
2014-11-03 06:22:04

CopyableCougar4 (82 views)
2014-11-01 23:36:41
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

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
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!