Thread: "Deciding" in runtime the type of a variable

  1. #16
    Registered User mikahell's Avatar
    Join Date
    Jun 2006
    Posts
    114
    You're still really not explaining what you want to happen. You're just saying "There is big variables! AND LITTLE Ones! AND BIGGER LITTLER ONES! AND NONE OF IT WORKS!!! AHH!!!!"...
    . Well, as I said in the first posts, everything works, I'm just trying to optimize stuff. And my variables are so big and heavy that my computer is sinking in the floor...

    But you know, its just that its hard to explain, it's just that I allocate a quantity of memory that is different for my objects, and I know that using a void pointer, (or other), I can use NEW to prepare an area of memory for any object, depending on what it needs, and then just by knowing the type Id of that object, I can call a function pointer to which I pass the address to the area of memory that objects occupy, but I can't sum it all for everything, because I want to use as less memory as possible, and I know that I could use for everything, the same mount of memory, which would make it simpler, but that's not what I'm looking for.

    I think making a game's hard, and I would like to let you think about how would you do it if you had many kind of stuff to handle. Just understand this: a game can have many kind of objects, can be items, can be enemies, etc... so the objects variables will not always be the same... But I don't even use derivates and stuffs, because I don't plan in trying to learn that yet...

    If there's more about "still not explaining what you want to do" well I can't really go farther and hand out my whole code like that... Just start playing games and help me figure out how they're done...


    Regardless of whether he should do it or not, the question he posed is "how can I do it?".
    Yeah, that's what I want to know, but its also about optimization, not changing language over and over, unless I decide to create one! But then why should I create some language of mine?
    Last edited by mikahell; 07-21-2006 at 05:15 PM.

  2. #17
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    There's Boost.Variant, but I'm with Sly: you should seriously reconsider your design. It seems you've created it with ActionScript in mind.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  3. #18
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,079
    Well then I stand with Prelude's suggestion, as well. Not with using a less strictly-typed language, but reconsidering your design. There have been so many games done in C++, that I find it hard to believe there isn't a better way to do whatever you want done. Either there is a work around or you're just treading into grounds you really don't need to go into. As I said in my first post, I feel like whatever you find this useful for, there is probably a better way.

    Oh by the way, I can teach you a better design for your game if you can teach me some action script basics. This is the best flash I've made so far. http://server6.theimagehosting.com/i...bleInLight.swf
    Sent from my iPadŽ

  4. #19
    Registered User mikahell's Avatar
    Join Date
    Jun 2006
    Posts
    114
    Well, what you have done in flash seems useless to me, (I don't say this to tell bad things), but I think that you seem to be able to do some great things in Flash. From what I believe you used to have 2 movieclips, with that ball rotating as it points to a "light" point with what you use trigonometry to rotate it... Well, its great work, but if you want help on something, I can't really figure out what help you need. But it's true that I'm thinking AS2 when I write in C++, it's because I fell in a Flash kettle when I was young (mwah ha!). But I can't do anything about it...

    I can tell that AS is so nice because you can code so badly how you want, but in the end, you have to know this:
    Code:
    var a = 10;
    a = "hello";
    It's something in Flash that is totally possible to do, and as you can see, since you don't specify a type when assigning a to 10, then to a string, I believe that behind the program there is a lot of resizing space for variables, and I decided to stop working with Flash when I realized from loop-test that Flash could only do 100 000 empty operations / second, while it was about 30 000 000 (or so) for C++... But I'd like to be the teacher sometimes

  5. #20
    pronounced 'fib' FillYourBrain's Avatar
    Join Date
    Aug 2002
    Posts
    2,297
    I should mention that even though I provided an answer, I also don't believe he should do it.

    I think what everyone is trying to say here is, give us the broader picture of why you want to do this and we'll give you better design ideas.
    "You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter

  6. #21
    Registered User mikahell's Avatar
    Join Date
    Jun 2006
    Posts
    114
    Well FYB, you should look in some recent post I have explained it all, but it's for a game, and I'm just trying up new things, but my ideas should be found at my "05:09 PM" post...

    But what's Boost.Variant? I feel like a fool but a pasted that in my code an it did nothing lol!

  7. #22
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,079
    Heh, there is no math involved in that animation. The light layer is just doing a 90 degree rotation through the motion tween. I don't know the first thing about action scripting syntax or what it's capable of. Anyway, as I said about your game design. Since I still don't really know what you're trying to accomplish it still looks to me like you're looking for polymorphism. The way your explaining your problems, that's what I'm thinking you need. I don't mean to insult your intelligence if you already know what it is, but I can give you an example of how to use it if you need.

    What kind of game are you making, may I ask?

    Quote Originally Posted by mikahell
    But what's Boost.Variant? I feel like a fool but a pasted that in my code an it did nothing lol!
    Boost is a set of third party libraries that look to be included into the next standard. You can google boost C++ if you're looking to install them, however if you're a nooblet like me, installing them can take quite a bit of time.
    Last edited by SlyMaelstrom; 07-21-2006 at 05:51 PM.
    Sent from my iPadŽ

  8. #23
    Registered User mikahell's Avatar
    Join Date
    Jun 2006
    Posts
    114
    Type of game? I'll go around the question and tell you that my main challenges (to myself) (and to learn) are to try to understand how a game that I like works, then try to "mimic" the game's engine, or just for the fun of making games... But currently I'm working on Legend of Zelda engine, and I try to mimic the ones found on the gameboy, so I play these games and at the same time I try to figure out how they work, then try to code them in Flash (before) than in C++... Because when you are able to do the work of these people, you feel really good! But yet in this one I'm just starting and I didn't want to push on too far with explaining in depths what I was planning to do...

    but making games is what makes me push really hard in programming, my first game ever was a 2000 lines of code Final Fantasy done on a graphical calulator (TI-80) while I was 4th grade at high-school! But I think though that by experience my design should "be" ok, but it makes me sick when I hear things that I'm not familiar with, like "Overrides" "Derives" and others like child class from another parent master's class...

  9. #24
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,079
    Quote Originally Posted by mikahell
    but it makes me sick when I hear things that I'm not familiar with, like "Overrides" "Derives" and others like child class from another parent master's class...
    Heh, well that's what Object Oriented programming is all about. I don't know why you were being so discreet about your idea... it's not like we're going to steal it from you. You can definitely create a Legend of Zelda type game in C++. You can make that game in several languages... though you choose a language like C++ not because people say it's great but for the advantages it offers.

    You should probably get very familiar with the three requirements of O-OP before trying to make this game if you want to do it in C++. That is Classes, Inheritance, and Polymorphism. You should also learn some basic data-structures and templates if you don't already. If you feel you're comfortable with all that, then you're ready to sit down, get out some paper and lay out your implementation.
    Sent from my iPadŽ

  10. #25
    Registered User mikahell's Avatar
    Join Date
    Jun 2006
    Posts
    114
    Hehe, it was not really about stealing from someone, but it just that I have some problem expressing myself when I have to talk about the games I make, because they are like clones from the originals and for this I don't want to get problem with copyrights so that's why I stay hidden in the dark... but I know "some" things about OOP, because I'm beggining college and so I know about these, but you know, our teachers teaches things very sloowly... Anyway, I know how to work with templates, inheritance and parent/child, encapsulation but my school-learnings don't help me at this point to take advantage of these things...

    To return to my discretion, its as I said, its just because I want to make some exact-fine copy of original games, but that implies in a sense getting sprites and music from the game and I don't suppose that this is completly legal, even though one wouldn't care if no one would no... Maybe I'm just taking precautions for nothing, maybe not, but for the time being, none of the 4 clone popular games I made got a foot on the web, for my security purpose of never seeing anyone telling me that I steal things up and make money with it...

  11. #26
    pwns nooblars
    Join Date
    Oct 2005
    Location
    Portland, Or
    Posts
    1,094
    I have seen several FF clones, a couple zelda clones, Ultima. Alot of people start with cloning games or features from games that they have played and liked. Shard of Dalaya is probably the most known clone. As long as you aren't trying to make money off it or distribute it as the original, I haven't seen many places that would care too much. 2d RPG style like that is hard new/cutting edge technology.

  12. #27
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    As long as you keep them for personal consumption, you'll be ok. Heck, you can even say Legend of Zelda without the (tm) thing

    Do as Sly suggested. Learn the programming language first. It is obvious you already have some knowledge of it. But it seems you are lacking on some fundamental concepts. OOP is one of these.

    EDIT: Oh, and RTTI stands for Run Time Type Identification. It is a feature of C++. I'm a complete newb to it as of yet. And a second look at its description after realizing no one followed on my suggestion, revealed why. It's not applicable to your problem.
    Last edited by Mario F.; 07-21-2006 at 07:43 PM.
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  13. #28
    Registered User mikahell's Avatar
    Join Date
    Jun 2006
    Posts
    114
    Then I suppose I'll have to wait for when I will learn more in school, but I will still try on and do things...

  14. #29
    Registered User Osaou's Avatar
    Join Date
    Nov 2004
    Location
    Stockholm, Sweden
    Posts
    69
    Why not study online? There are countless C++ tutorials on the net... =)
    For example:
    http://www.cplusplus.com/doc/tutorial/introduction.html
    http://www.cprogramming.com/tutorial/lesson1.html

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. Replies: 6
    Last Post: 07-29-2008, 04:37 AM
  3. Need some help...
    By darkconvoy in forum C Programming
    Replies: 32
    Last Post: 04-29-2008, 03:33 PM
  4. Replies: 6
    Last Post: 04-10-2008, 11:49 PM
  5. Using VC Toolkit 2003
    By Noobwaker in forum Windows Programming
    Replies: 8
    Last Post: 03-13-2006, 07:33 AM