Iteration and object instancing

This is a discussion on Iteration and object instancing within the C++ Programming forums, part of the General Programming Boards category; Edit: This issue is solved, thank you. The main problem here is with syntax. What I'm trying to do is ...

  1. #1
    Registered User Winter Warrior's Avatar
    Join Date
    Aug 2010
    Location
    Finland
    Posts
    3

    Question Iteration and object instancing

    Edit: This issue is solved, thank you.

    The main problem here is with syntax. What I'm trying to do is instancing Ogre::Entity* type objects in a for loop, but they all need to be uniquely named for the scene to render. Obviously, when the function reaches the Ogre::Entity* entity_name line, the string variable entity_name is replaced with an Entity type object (no longer a string).

    The bottom line: Is there a way for the object instancing to read the contents of a string variable and name the new instance after the string content? Like Ogre::Entity* hex_deep_ocean_0 = ... where the hex_deep_ocean_0 part is retrieved from a string variable.

    (Note: I've added short to string conversion code after that screenshot was taken. The string operations are working, I just don't know how I'm supposed to make object creation iterable.)
    Attached Images Attached Images  
    Last edited by Winter Warrior; 08-04-2010 at 03:45 AM.

  2. #2
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,810
    Are you just asking how to concat a string with an int?
    Code:
    std::ostringstream entityNameStream;
    entityNameStream<<"hex_deep_ocean_"<<deep_oceans;
    
    string enity_name = entityNameStream.str();
    Your Orge stuff should be name different that your strings. See below
    Code:
    Orge::Entity* orge_entity_name = mSceneMgr->createEntity(entity_name, "blah");
    Last edited by prog-bman; 08-03-2010 at 01:24 PM.
    Woop?

  3. #3
    Registered User Winter Warrior's Avatar
    Join Date
    Aug 2010
    Location
    Finland
    Posts
    3
    Quote Originally Posted by prog-bman View Post
    Are you just asking how to concat a string with an int?
    Code:
    std::ostringstream entityNameStream;
    entityNameStream<<"hex_deep_ocean_"<<deep_oceans;
    
    string enity_name = entityNameStream.str();
    Your Orge stuff should be name different that your strings. See below
    Code:
    Orge::Entity* orge_entity_name = mSceneMgr->createEntity(entity_name, "blah");
    Wish it was that simple. The code does compile right, but the .exe crashes when it's supposed to render the scene. The graphics engine probably doesn't like having 80 entities called ogre_entity_name in the scene. But they're pointers, they're deleted after the for cycle ends, so that shouldn't be a problem... I'll have to sleep on it, too tired to think straight.

    Thanks for the help.

  4. #4
    Registered User
    Join Date
    Nov 2008
    Posts
    26
    You cannot dynamically assign names to new instances because the names of identifiers is a compile-time mechanism.
    I think you are confusing the unique identifier of an object and uniqueness of the object. You can allocate new unique objects using a same identifier as you are doing in a loop. I suspect the problem is somewhere else.

  5. #5
    Registered User Winter Warrior's Avatar
    Join Date
    Aug 2010
    Location
    Finland
    Posts
    3
    Quote Originally Posted by salquestfl View Post
    You cannot dynamically assign names to new instances because the names of identifiers is a compile-time mechanism.
    I think you are confusing the unique identifier of an object and uniqueness of the object. You can allocate new unique objects using a same identifier as you are doing in a loop. I suspect the problem is somewhere else.
    Yeah, I came to the same conclusion this morning when I was reading through the code. The map is now rendering correctly, problem solved. Thanks to everyone for helping.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. List iteration problem, it resets values
    By Mike Borozdin in forum C++ Programming
    Replies: 4
    Last Post: 11-30-2006, 09:42 AM
  2. From script to C to C++
    By VirtualAce in forum Game Programming
    Replies: 2
    Last Post: 09-11-2006, 05:35 AM
  3. Our First Article - Searching Techniques By Prelude
    By kermi3 in forum Article Discussions
    Replies: 17
    Last Post: 01-31-2005, 05:48 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21