Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 476 477 [478] 479 480 ... 796

Author Topic: if self.isCoder(): post() #Programming Thread  (Read 887517 times)

XXXXYYYY

  • Bay Watcher
  • Been a long time.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7155 on: April 12, 2015, 08:47:36 pm »

Quote
2000 lines
How much stuff is handled in that file?
Well, it has all the stuff for world generation, including the temperature, moisture, and biome functions. But really it could do with some pruning, there are a few functions that I don't even use anymore.

Also, Reelya, I added the namespace, and now it just says this for an error:
Code: [Select]
Release\obj\GameMap.o:GameMap.cpp:(.text+0x6323): undefined reference to `MapSystem::NatureRegion::NatureRegion()'

So, I am guessing that there is something wrong with this line, without it there is no error:
Code: [Select]
NatureRegions.push_back(new NatureRegion);
Just to note, NatureRegions is the vector containing the regions, it could probably use a better name. I'm not yet, quite sure of any other ways to do what I want that line to do.
Do you have a default constructor? That's what it looks like it might be, from what I know, which isn't much. If you gave it a different constructor, it assumes that "you got dis", and doesn't autodefine the no-argument constructor anymore, which would result in that error.
Logged
Oooooooo. I know. ClF3. That should be a fun surprise.

HavingPhun

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7156 on: April 12, 2015, 09:29:04 pm »

Nope, that didn't change anything. But, thank you anyways. Also, this may be important, this is the declaration of the vector NatureRegions.

Code: [Select]
std::vector <NatureRegion*> NatureRegions;
Logged

Rose

  • Bay Watcher
  • Resident Elf
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7157 on: April 12, 2015, 11:10:55 pm »

So, I'm working on some graphics tutorials with some folks, generally using C++ with OpenGL or OpenGL-like stuff. Intention being minimal explanation outside the code itself, using simple, understandable coding style to do so.

Question: what is the most confusing part of this code? Or in general, what would most keep you from arbitrarily modifying it into something with similar code but different results? https://github.com/jalway/tut0

seems pretty understandable so far. Simple, and to the point. I'll have to go through it more thoroughly so see if there's something I don't get.
Logged

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7158 on: April 13, 2015, 03:11:22 am »

First up, you seem to have the .h and .cpp files swapped around. Is that a typo or is your actual program like that? .h files are meant to have function declarations and class definitions, and .cpp files are meant to have the specific code. It's the .cpp files which are compiled into ".o" files, which are then linked together into the executable. you should never, ever see a situation where an "include" has a .cpp file as the target, only a .h file.

Namespaces operate similarly to a class, actually:

namespace stuff
{
   class foo
   {
   };
   function bar()
   {
   };
};

They would then be refered to (outside of the namespace) similarly to static members of a class:

stuff:foo

stuff:bar()

If find that if you have a .h file full of globals and you want to de-spaghettify things then wrapping it all in a namespace can be a helpful first step in organizing what needs to go where (e.g. making it into a class with static members instead). Being sort of half-way between a bunch of globals and a class makes namespaces handy for refactoring code into a more object oriented fashion, and they can be useful to indicate which header file something came from, e.g. I often put "namespace input" around my input handling code, so everything there is part of the same space, even if they're different functions and classes.

Another nice thing is that namespaces can be discontinuous:

namespace foo
{
    // define foo stuff
};

// another file

namespace foo
{
    // define more foo stuff, or use foo stuff without the "foo::"
};

They also have no memory overhead, unlike a class, since they're just a name.
« Last Edit: April 13, 2015, 03:46:09 am by Reelya »
Logged

Orange Wizard

  • Bay Watcher
  • mou ii yo
    • View Profile
    • S M U G
Re: if self.isCoder(): post() #Programming Thread
« Reply #7159 on: April 13, 2015, 03:59:18 am »

See, this is why I use Python.
Logged
Please don't shitpost, it lowers the quality of discourse
Hard science is like a sword, and soft science is like fear. You can use both to equally powerful results, but even if your opponent disbelieve your stabs, they will still die.

Putnam

  • Bay Watcher
  • DAT WIZARD
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7160 on: April 13, 2015, 04:06:08 am »

EDIT: oh shit i had something here but... something weird happened when I was doing my standard 3-second-later-edit-upon-seeing-mistake? Any way to get that back? This has never happened before.

Telgin

  • Bay Watcher
  • Professional Programmer
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7161 on: April 13, 2015, 07:39:13 am »

you should never, ever see a situation where an "include" has a .cpp file as the target, only a .h file.

While this is sound advice, it's worth noting that it is possible to use .c, .C and .cpp (or actually any text file I believe) in an #include statement.  The compiler is merely doing a text replace by dumping the indicated file in place of the #include.  I don't think I've ever seen it used in practice, but it's possible.  About the only use of it that I can think of is code that does conditional compilation and the branches are long enough to use multiple files, but I'd try to avoid it even then.

So, I'm working on some graphics tutorials with some folks, generally using C++ with OpenGL or OpenGL-like stuff. Intention being minimal explanation outside the code itself, using simple, understandable coding style to do so.

Question: what is the most confusing part of this code? Or in general, what would most keep you from arbitrarily modifying it into something with similar code but different results? https://github.com/jalway/tut0

I'm going to admit that I'm impressed that it's possible to create an OpenGL window that can render anything with so few lines.  That said, I learned OpenGL back when the only way to get things to render was to use glVertex3f and its cousins to send vertices to the GPU.  I think that's called immediate mode these days?

Anyway, the only thing that I was curious about while looking through it is where the libraries came from that are letting you create a Win32 window with such little code.  I guess it's not the point of the tutorial to show Win32 window creation, message pumps and all of that nastiness, so it makes sense to use a library to manage that for you.
Logged
Through pain, I find wisdom.

Soadreqm

  • Bay Watcher
  • I'm okay with this. I'm okay with a lot of things.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7162 on: April 13, 2015, 02:50:59 pm »

So, I'm taking keyboard input through Microsoft.Xna.Framework.Input.KeyboardState. I thought it worked just fine, until I went looking through the Keys enum for the '<' and '>' keys. It doesn't have them, obviously. KeyboardState reports the status of the physical keys, not characters, and on a US-layout keyboard, '<' and '>' are behind the shift key.

Problem is, I don't have a US-layout keyboard. I have a Finnish keyboard, with umlauts instead of brackets, and the comparison signs scrunched between 'Z' and left shift. The crude solution would be to figure out which Key that key corresponds to (assuming there is one), and check that instead, but I'd like there to be a way to just check for a character typed instead of a button pressed. Does anyone here know if I can do that with XNA?
Logged

MagmaMcFry

  • Bay Watcher
  • [EXISTS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7163 on: April 13, 2015, 03:08:31 pm »

I looked at the documentation, and it looks like you can't do that using XNA, since XNA is shitty and doesn't use callbacks (and it doesn't store an event history either). XNA only allows you to ask which physical keys are currently pressed, nothing else. So yeah, if you want to do something with the individual keystrokes (with the generated Unicode symbols) then you might want to stop using XNA.
Logged

HavingPhun

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7164 on: April 13, 2015, 03:29:32 pm »

First up, you seem to have the .h and .cpp files swapped around. Is that a typo or is your actual program like that?
Once again, sorry about that. I have been copy pasting the bulk of the code and then filling in the bits such as includes. I mistaking switched them up.

Explanation of namespaces.
Hmm, they seem very useful, beforehand I just overlooked them, seeing them as some sort of feature I don't feel the need to use. Anyways, I still haven't figured out what the problem is with the code, or what is wrong on the specific line that causes it. I am going to take a look at a few c++ tutorial pdfs I have downloaded, and see if I can figure anything out.
Logged

Soadreqm

  • Bay Watcher
  • I'm okay with this. I'm okay with a lot of things.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7165 on: April 13, 2015, 03:53:53 pm »

I looked at the documentation, and it looks like you can't do that using XNA, since XNA is shitty and doesn't use callbacks (and it doesn't store an event history either). XNA only allows you to ask which physical keys are currently pressed, nothing else. So yeah, if you want to do something with the individual keystrokes (with the generated Unicode symbols) then you might want to stop using XNA.
Oh, well. I think I'll just work around it for now.
Logged

HavingPhun

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7166 on: April 13, 2015, 06:01:02 pm »

So, I am completely lost. Here: http://stackoverflow.com/questions/13372753/best-methods-for-dynamically-creating-new-objects , they suggest that this should work.

Code: [Select]
class Example
{
   Example();
   ~Example();

   int var1;
   int var2;
}

std::vector <Example> ExampleVector;
ExampleVector.push_back(Example());
I tried that, both within the respective function, and within main to make sure it isn't caused by something else. Either way I just get an error that says "undefined reference to `MapSystem::NatureRegion::NatureRegion()' ". I also tried every other variation of it on that site, and nothing works. It doesn't build using any of the methods, just errors galore. So, I am stuck until I can figure this out.
Logged

MagmaMcFry

  • Bay Watcher
  • [EXISTS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7167 on: April 13, 2015, 06:12:53 pm »

Well, have you actually implemented MapSystem::NatureRegion::NatureRegion()? Is that method visible from where you're calling it? Can you pastebin all the relevant files, please?
Logged

HavingPhun

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7168 on: April 13, 2015, 06:30:16 pm »

Well, have you actually implemented MapSystem::NatureRegion::NatureRegion()? Is that method visible from where you're calling it? Can you pastebin all the relevant files, please?
http://pastebin.com/Envmn6MG

For GameMap.cpp I just included the offending function. The line in particular that is causing the problem, that I was discussing above, is line 49. The class NatureRegion is in the file GameMap.h. The definition of the vector NatureRegionsContainers is at the bottom of the class GameMap, in the file GameMap.h. Thank you ahead of time for any assistance given. The errors are at the very bottom of the pastebin link.
Logged

Moghjubar

  • Bay Watcher
  • Science gets you to space.
    • View Profile
    • Demon Legend
Re: if self.isCoder(): post() #Programming Thread
« Reply #7169 on: April 13, 2015, 07:26:51 pm »

While this is sound advice, it's worth noting that it is possible to use .c, .C and .cpp (or actually any text file I believe) in an #include statement.  The compiler is merely doing a text replace by dumping the indicated file in place of the #include.  I don't think I've ever seen it used in practice, but it's possible. 

Pretty sure Handmade Hero does just that (Unity build): https://forums.handmadehero.org/index.php/forum?view=topic&catid=4&id=454
Logged
Steam ID
Making things in Unity
Current Project: Demon Legend
Also working on THIS! Farworld Pioneers
Mastodon
Pages: 1 ... 476 477 [478] 479 480 ... 796