Page 2 of 2 FirstFirst 12
Results 21 to 25 of 25
Like Tree5Likes

Thread: JAVA storing objects

  1. #21
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,820
    Rep Power
    19

    Default Re: JAVA storing objects

    Quote Originally Posted by santa View Post
    Well that's what im doing =) Sense i don't know how many "objects" are going to be in each tile ... I'm guessing I should use an ArrayList. But if i remember correctly that does allocate more memory? Will that cause a problem when i do it in 1000000 objects?

    Thanks again
    If you know how big your Map is then use a fixed 2D array of whatever size.
    So you have a Tile[1000][1000].
    The Tile will hold data on what is in a particular tile. Note this should be fixed (or long lived) objects.
    That would probably be, as you say, an ArrayList.
    Don't worry about memory at the moment. You either need to store this stuff or you don't, and an ArrayLists overhead is pretty small.

    Stuff that moves around (eg characters) don't belong in the Tile model.

    That gives you your Model.
    Your View will take that Model and turn it into graphics.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  2. #22
    santa's Avatar
    santa is offline Senior Member
    Join Date
    Nov 2009
    Location
    Sweden
    Posts
    208
    Rep Power
    5

    Default Re: JAVA storing objects

    Quote Originally Posted by DarrylBurke View Post
    The more I read your posts, the more I feel that you are mixing the game state -- the model -- and its visual representation -- the view. Try to achieve a separation of the two, even if you don't go for full MVC.

    Then you only have to store the state, the model, which should be orders of magnitude smaller than storing the entire view + state. The view will walk the model and build itself.

    db
    Well you are probably correct. But im getting a better view of things now i think but i have no idea what you mean by model and game state ? ;) I'm just freestyling to see if I can make a game or not =P I have NO previous game developing experience and low overall experience with java ...

  3. #23
    santa's Avatar
    santa is offline Senior Member
    Join Date
    Nov 2009
    Location
    Sweden
    Posts
    208
    Rep Power
    5

    Default Re: JAVA storing objects

    Quote Originally Posted by Tolls View Post
    If you know how big your Map is then use a fixed 2D array of whatever size.
    So you have a Tile[1000][1000].
    The Tile will hold data on what is in a particular tile. Note this should be fixed (or long lived) objects.
    That would probably be, as you say, an ArrayList.
    Don't worry about memory at the moment. You either need to store this stuff or you don't, and an ArrayLists overhead is pretty small.

    Stuff that moves around (eg characters) don't belong in the Tile model.

    That gives you your Model.
    Your View will take that Model and turn it into graphics.
    So that means im on the correct track =)
    "Don't worry about memory at the moment" ... The last time i didn't worry about something I ended up with lagg and rewriting the whole class no offence but I believe its better to worry about it now then be sorry later ;) ... (not that I think the ArrayList will slow the program) just saying ... that was a pain =P
    Thanks for your time and patience =)

  4. #24
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,820
    Rep Power
    19

    Default Re: JAVA storing objects

    The idea of a model (or game state) is not game specific.
    It's a general development style (I managed to avoid 'paradigm' there...blast!).

    Take chess. The game state (the model) would have a board, and pieces, and those pieces would have a location. There'd be two sides.
    etc etc.

    None of that worries about the view (ie how it is displayed).

    It should be possible to code that without any GUI at all.
    santa likes this.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  5. #25
    santa's Avatar
    santa is offline Senior Member
    Join Date
    Nov 2009
    Location
    Sweden
    Posts
    208
    Rep Power
    5

    Default Re: JAVA storing objects

    Thanks ... and also was there not a way in java to make a "frame" inside of a Panel ? I cant really remember ... pointer to where i can read about it?

Page 2 of 2 FirstFirst 12

Similar Threads

  1. Replies: 2
    Last Post: 11-06-2011, 07:19 PM
  2. Replies: 6
    Last Post: 11-02-2011, 03:38 AM
  3. Storing objects in an array list?
    By Moedig in forum New To Java
    Replies: 3
    Last Post: 10-27-2011, 06:39 PM
  4. Storing objects
    By paul1024 in forum New To Java
    Replies: 5
    Last Post: 04-30-2011, 06:12 AM
  5. Storing objects directly with db4o
    By german in forum JDBC
    Replies: 0
    Last Post: 05-12-2009, 08:22 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •