Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 245 246 [247] 248 249 ... 796

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

Siquo

  • Bay Watcher
  • Procedurally generated
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3690 on: January 21, 2013, 02:59:02 pm »

How on earth is it possible to do stuff without pointers?!

Every time I try to make local objects, but every time I eventually have to go back to using pointers :(
Logged

This one thread is mine. MIIIIINE!!! And it will remain a happy, friendly, encouraging place, whether you lot like it or not. 
will rena,eme sique to sique sxds-- siquo if sucessufil
(cant spel siqou a. every speling looks wroing (hate this))

GlyphGryph

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3691 on: January 21, 2013, 03:00:56 pm »

I don't even understand the point of /ever/ using non-pointers. In fact, the whole concept of copying being standard behaviour boggles me.

This might be because I'm a Rubyist by profession, and like most interpreted languages everything is done by reference by default.
Logged

Virex

  • Bay Watcher
  • Subjects interest attracted. Annalyses pending...
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3692 on: January 21, 2013, 03:14:02 pm »

The reason for that is that C++ doesn't distinguish between objects and built-in types. A variable containing an object actually contains the object, not a reference to the object. So, since the object is treated like any other compound type, it just gets copied whole and ends up on the stack. It's one of those close-to-the-metal things C++ is known for.
Logged

MorleyDev

  • Bay Watcher
  • "It is not enough for it to just work."
    • View Profile
    • MorleyDev
Re: if self.isCoder(): post() #Programming Thread
« Reply #3693 on: January 21, 2013, 03:28:39 pm »

I don't even understand the point of /ever/ using non-pointers. In fact, the whole concept of copying being standard behaviour boggles me.

This might be because I'm a Rubyist by profession, and like most interpreted languages everything is done by reference by default.

Stack allocation is generally faster than heap allocation. Couple this with if something is about 16 bytes or smaller, it's more speed-efficient to copy by value than to pass a const reference in situations where the compiled can't optimise away the reference/copy (obviously copying logic in an object destroys this statistic somewhat). For the role of C++ (and the time it originated) using values by default makes sense.

Whilst a (JIT or otherwise) compiler in modern times can often make a reasonably intelligent decision about allocating objects on stack vs heap, it can't always. And in those situations, you have to either use a much less expressive and intuitive design (which tends to increase the chance of bugs and unreadable code. Which is bad.), or accept you want to do something the language isn't suited for and move to a different language. This is why C# has the struct, which basically scream in the compiler's ear "This should probably go on the stack!".

To use the lowest hanging fruit example, the "first instinct implementation" of a functional mathematical Vector class in Java tends to be very inefficient because the compiler still doesn't/can't make intelligent enough decisions about it. You get a lot of slowdown from the Vectors being new'd and collected, as the Project Zomboid developers learned the hard way...
« Last Edit: January 21, 2013, 04:13:42 pm by MorleyDev »
Logged

Siquo

  • Bay Watcher
  • Procedurally generated
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3694 on: January 21, 2013, 05:09:44 pm »

Stack allocation is generally faster than heap allocation.
I knowww..... but there appear to be SO FEW use cases, and so much recycling of already allocated heap can be done!
Logged

This one thread is mine. MIIIIINE!!! And it will remain a happy, friendly, encouraging place, whether you lot like it or not. 
will rena,eme sique to sique sxds-- siquo if sucessufil
(cant spel siqou a. every speling looks wroing (hate this))

MorleyDev

  • Bay Watcher
  • "It is not enough for it to just work."
    • View Profile
    • MorleyDev
Re: if self.isCoder(): post() #Programming Thread
« Reply #3695 on: January 21, 2013, 05:12:56 pm »

Nowadays yeah, with Moore's law and those optimisations C++ simply isn't needed for a lot of projects. But back between when C grew up? A lot of the optimisations made by managed languages were pipe dreams. The trade-off in memory or CPU was just too much of a precious resource to waste. So C++ took the C approach, and even when C++ was first developed it was still the better way. All other things being equal, well-optimised C++ will still win in most situations against other languages being well-optimised, but thanks to Moore's law we don't need to make those optimisations and the advantages from a business perspective provided by using languages like C# means you wouldn't use C++ anyway in a lot of business situations. That potential speed just isn't worth the time and risks.

At work we use C# to manage our servers and it works beautifully. We're needing to optimise the legacy code, but C# itself isn't the issue there. We've just learnt a lot about better ways to code. In fact one of the "discoveries" is that simple, well designed and loosely coupled code in C# is more than efficient enough. No need for those clever hacks, simple code is beautiful.
« Last Edit: January 21, 2013, 05:23:55 pm by MorleyDev »
Logged

Nadaka

  • Bay Watcher
    • View Profile
    • http://www.nadaka.us
Re: if self.isCoder(): post() #Programming Thread
« Reply #3696 on: January 21, 2013, 06:15:01 pm »

Fortunately for java 99% of the time, heap space is already allocated. One of the few places where java slightly outperforms standard c++ is in the creation and destruction of a large number of objects on the heap.
Logged
Take me out to the black, tell them I ain't comin' back...
I don't care cause I'm still free, you can't take the sky from me...

I turned myself into a monster, to fight against the monsters of the world.

MorleyDev

  • Bay Watcher
  • "It is not enough for it to just work."
    • View Profile
    • MorleyDev
Re: if self.isCoder(): post() #Programming Thread
« Reply #3697 on: January 21, 2013, 06:22:46 pm »

Which still doesn't work for functional code vs the stack, hence why a Vector2 that's functional is a bad idea...

Anyway, sudden change of topic: Has anybody else had immense trouble getting CMake to work for MinGW? Even when I completely clear the Path so the MinGW compiler is the only thing on it, I get errors related to the CreateProcess function :(

EDIT: Nevermind, running
"C:\cmake\bin\cmake" -G "MinGW Makefiles" -DCMAKE_MAKE_PROGRAM="C:\Mingw\bin\make" from sh.exe of all things worked 0_o I'm just gonna throw my hands up and say "fuck it, it works".
« Last Edit: January 22, 2013, 04:15:28 am by MorleyDev »
Logged

eerr

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3698 on: January 22, 2013, 01:26:25 am »

So what do people use for graphics? I just want something fast and non confusing with transparency. Is Unity reasonable?
Logged

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #3699 on: January 22, 2013, 01:53:51 am »

I use SDL+libtcod for ASCII-like games!
And Allegro seems to be nifty for 2D graphics. Unity is C#/C++(paid) IIRC...
SDL+(lots of extra libraries) or SMFL are reasonable choices, too.
3D graphics go either Unity or OpenGL, usually o_O
Logged

bay12 lower boards IRC:irc.darkmyst.org @ #bay12lb
"Oh, they never lie. They dissemble, evade, prevaricate, confoud, confuse, distract, obscure, subtly misrepresent and willfully misunderstand with what often appears to be a positively gleeful relish ... but they never lie" -- Look To Windward

alway

  • Bay Watcher
  • 🏳️‍⚧️
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3700 on: January 22, 2013, 01:56:48 am »

So what do people use for graphics? I just want something fast and non confusing with transparency. Is Unity reasonable?
Unity is a piece of cake. Here's the basics: http://www.unity3dstudent.com/category/modules/essential-skills/
As for speed, it's not the fastest thing out there, but it's more than reasonable for pretty much anyone whose game isn't based entirely around physics or other high-demand processes. Even Kerbal Space Program uses it.

Additionally, while the Unity Pro version does cost money, the normal version is free. The main differences being a few advanced features are cut from the normal version, as well as having a splash screen and small logo onscreen.

It goes really well with Maya, if you have that already. I haven't tried it with Blender, but I suspect it would be just as easy, what with Blender exporting to pretty much every file imaginable due to being open source.

TBH, Unity is a great choice for most beginners, as it requires very little programming knowledge, and the features it doesn't support are really only used by more advanced coders anyway. It's also great for prototyping.


However, if you want to have stories to tell your kids about how 'back in my day, we had to code uphill both ways in the snow,' learn DirectX or OpenGL with shaders first. Doing that before going to university pretty much pushed me up to the top of my class for that year's students. Because after graphics programming, any other programming seems trivial. :P
« Last Edit: January 22, 2013, 02:10:10 am by alway »
Logged

Valid_Dark

  • Bay Watcher
  • If you wont let me Dream, I wont let you sleep.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3701 on: January 22, 2013, 03:25:28 am »

RAAAAAAAAAAAAGEEEEEEE
so I finally finish the first release of this one program,
I compile it and run it, everything goes smoothly,
but then I go to run it from the .exe and it doesn't run,  double check that all resources and .dll's are in place, they are, try running it again, doesn't run.
Copy all of the code, start new project, paste all of the code, move every item from that folder into new project folder, build and run, and that won't even run from inside the IDE,  a little bit of debugging points out that it's having an issue loading a certain PNG, it's in the right place.
why would it run in the IDE in one instance of the code, but not the other?

Nevermind, fixed it,
was missing zlib,  this is the second project where for somereason I leave out zlib and it makes me go on a rage for 2 hours trying to fix shit.
fuck you zlib1.dll I hate you.
« Last Edit: January 22, 2013, 03:53:44 am by Valid_Dark »
Logged
There are 10 types of people in this world. Those that understand binary and those that don't


Quote
My milkshake brings all the criminals to justice.

alway

  • Bay Watcher
  • 🏳️‍⚧️
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3702 on: January 22, 2013, 03:53:51 am »

Dunno which platform, but it could be an issue with directories it's searching.

As for why it wasn't running from the .exe: the IDE will likely treat it as if it is in a different location. Typically it treats it like it is in the main folder of your project, but the actual .exe is stored in a subdirectory. On CodeBlocks work, the .exe is in ./bin/Release/program.exe, while the IDE treats it like it is in ./program.exe. This will break any relative paths.
Logged

Siquo

  • Bay Watcher
  • Procedurally generated
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3703 on: January 22, 2013, 03:54:46 am »

So what do people use for graphics? I just want something fast and non confusing with transparency. Is Unity reasonable?
SFML is a valid option, it's like a lightweight SDL.

I'm just gonna throw my hands up and say "fuck it, it works".
And that is how you Make.
Logged

This one thread is mine. MIIIIINE!!! And it will remain a happy, friendly, encouraging place, whether you lot like it or not. 
will rena,eme sique to sique sxds-- siquo if sucessufil
(cant spel siqou a. every speling looks wroing (hate this))

Valid_Dark

  • Bay Watcher
  • If you wont let me Dream, I wont let you sleep.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3704 on: January 22, 2013, 04:46:56 am »

Dunno which platform, but it could be an issue with directories it's searching.

As for why it wasn't running from the .exe: the IDE will likely treat it as if it is in a different location. Typically it treats it like it is in the main folder of your project, but the actual .exe is stored in a subdirectory. On CodeBlocks work, the .exe is in ./bin/Release/program.exe, while the IDE treats it like it is in ./program.exe. This will break any relative paths.

yes, the IDE treats it as if it's not in /bin/ sub directory, but zlib.dll wasn't in that folder, and it was working from the IDE, I tried copying everything from that folder multiple times to the subdirectories where the .exe's were and it never worked, so zlib wasn't there but it still ran though the IDE.
but w/e doesn't matter, it works now.
Logged
There are 10 types of people in this world. Those that understand binary and those that don't


Quote
My milkshake brings all the criminals to justice.
Pages: 1 ... 245 246 [247] 248 249 ... 796