Jump to content

  • Log In with Google      Sign In   
  • Create Account


smr

Member Since 16 Jul 2004
Online Last Active Today, 08:54 AM
-----

#5091397 Why are static variables bad?

Posted by smr on 03 September 2013 - 01:47 PM

Right. Static variables are bad when used incorrectly. Making static variables globally accessible invites the programmer to access that variable at any point in the code without any clear indication from outside that code that there is a dependency on that global variable. This makes it impossible to test or reuse software components as individual units. Incorrectly used global static variables also threaten to wreak havoc all over your codebase whenever you attempt to change the way the variable is used or what it means. The alternative to using global static variables is usually to implement form of dependency injection so that any unit that depends on the variable will have its dependency clearly and explicitly indicated. Often this also has the benefit of compile-time error checking -- if you forget to pass that variable to your constructor or method that depends on it, then it won't compile.

 

Another potential drawback to using bare statics is that they are not thread safe. Any thread can access and modify the static without any sort of locking.




#5083956 Event Handlers In C

Posted by smr on 07 August 2013 - 02:52 PM

I would omit the name field for the event listeners. The only reason I can think that you'd want to have names attached to your event callbacks is so that you can identify them later for removal or to ensure that the same callback isn't registered for the same event more than once. Since this is C it's easy enough just to use the callback's address as the identifier. This will save some space in each callback, as well as spare you from having to work with strings (which in C, sucks pretty hard).




#5081687 Oh my glorious code!

Posted by smr on 30 July 2013 - 06:57 AM


I don't have any code from when I was that age, as around the age of 14 or so, an HDD crash had wiped out everything I had before this point

 

Same, only my HDD was random girly-pop cassette tapes I "found" somewhere in the vicinity of my sister's tape player...




#5078062 Emo framework for mobile games?

Posted by smr on 16 July 2013 - 12:17 AM

 
Dude, you realize that pygame's core is written on c++ right? Same is truth for most part of kivy (some of its classes are still use python).
I hardly see how its performance can be a problem on the logic of the game (it will be an incredible small performance lost if you consider the cost of rendering), and even if it is, use cython to optimize your code and you reach the C speed.
I recomend reading this: http://docs.cython.org/src/quickstart/cythonize.html
 


Yes.

Have you written anything using pygame? Pygame is not a game engine where most of the work is coded in high performance C code. There is no "render my scene and call these functions when stuff happens." Pygame does not have a "render_mesh" function. There is no "pathfind_astar" function there for you. There isn't even a "render my 2D scrolling tile map" function. You'll be coding these tight loops in python, and they will be slow because python is slow. On top of that, most of your calls to pygame APIs will need to cross the python to native ABI bridge. Marshaling these calls from python is slow, slow, slow. Each primitive you draw, each OpenGL call, every call to blit a surface will incur significant overhead. Not to mention many mobile devices have as high and in some cases higher screen resolutions than a typical desktop, which introduces even more overhead because you will probably be doing more blitting and drawing of primitives. AND further again, using high resolution images and textures, meaning more memory pressure, meaning ultimately to even more GC stutter.

So, dude. I know all about pygame. I use it. I love it. It's not for anything other than the
simplest of mobile games.


#5077933 Emo framework for mobile games?

Posted by smr on 15 July 2013 - 01:05 PM


I do NOT intend to use game makers, because they are wrong. You should have to code your game and not have these "Easy Options".

 

If you are determined to avoid "easy options" on vague emotional notions of them being wrong, then you're going to have a bad time. Game development is hard and time consuming. My gut tells me that unless a developer is willing to cut a corner now and then, or go the easy route, she'll never see a project through to completion. Besides, how easy is too easy? Where's the line drawn? Personally, I don't think you're a real programmer unless you do it all in assembly. All these "programmers" using C or C++ to code are amateurs. I'm talking to you, John Carmack. happy.png

 

More seriously, I would encourage you to not to immediately discredit "easy options," because no matter how much easier a game maker is to use over straight-up coding, game development is still hard. 

 

I can't speak to all of the options you've listed above, but I know something about a few of them:

 

Android SDK - It's only "hard to use" in that it is not a framework designed for game development. It provides access to the hardware and operating system services. Java code running against the SDK will be slower than well written C or C++ code, sometimes significantly. Carefully written Java can be fast on Dalvik (Android's Java VM), but it's not easy to do right. Just like in C or C++ you need to be very aware of how you're allocating memory in Java otherwise you'll have to deal with the garbage collector causing stutters in your framerate. I think this is why many iOS usually feels smoother than Android, but that's just a gut feeling. I have no evidence and don't have the inclination to look for some.

 

Kivy - Kivy is built on python and I think for anything beyond a simple game you will hit the performance wall.

 

MonoGame - You do not need to buy Xamarin studio to use MonoGame. MonoGame is free of cost to use. People are having success with MonoGame, but keep in mind you will have some of the same performance issues as you would if using the Android SDK. Mono runs on a virtual machine with a generational garbage collector. If you're not nice to it, it will bite you.

 

PyGame - Love pygame on the desktop, but, again, I think it would be too slow for anything but simple games. Also not very polished.




#5069427 Procedural Content Generation. Please Help

Posted by smr on 13 June 2013 - 08:27 AM

That's a pretty good way of doing it. I would recommend also implementing scaling on some of your cookie cutter rooms, that way you can randomly change their sizes. This will make it less obvious that each floor of your dungeon is just a puzzle of the same rooms.

 

Also I would avoid the "rooms connected by very long hallways" type of random generated content that you see in roguelikes like angband, rogue or nethack, unless it's intentional for a specific section, like a cave or somesuch. No one would ever build a structure this way, so it makes no sense to do it in your game. But that's just a pet peeve of mine.




#5068009 Avoiding the C++ chicken or egg problem

Posted by smr on 07 June 2013 - 07:39 AM

Aha! I detect here a fellow connoisseur of the fine art of sarcasm and hyperbole.

 

From what I've read he's frequently condescending from a "I know better" standpoint, which is typical I think of lots of developers, anyway. I know I was the same way when I landed my first gig probably thirteen years or so ago, but I've learned throughout the years I usually DON'T know better, or at least, don't know all the reasons why someone chose to do something a different way than I think I would have. I've found that if I take a step off my soapbox and let someone tell me how she came to do something a specific way, I might have come to the same or similar implementation. But I've not experienced his sarcasm or hyperbole ph34r.png




#5060323 Custom window GUI system

Posted by smr on 08 May 2013 - 09:10 AM

If you're creating a map/level editor and asking yourself "how do I create a gui?," then you're using the wrong tools. A map editor is a GUI application, and C++ is not the best tool for that job. Java with AWT/Swing, Python with wxPython or similar, C# with Mono are in my opinion your best bets for multiplatform GUI applications.

 

That being said, since you insist on putting your game on hold to create a GUI system, some people have had some success with immediate mode GUIs in short time frames. Google for "imgui" and you'll find many tutorials. I recommend Sol on Immediate Mode GUIs. IMGUIs can be quick to get up and running, but in my opinion are very unwieldy because you will be hard-coding your GUI layout. I don't like them. I recommend that while you're following any of these tutorials, keep in the back of your head the idea that you will want to evolve this immediate mode system into a retained-mode system with layout containers that can arrange your GUI controls for you. Hard coding "drawButton(100, 100, 50, 50, rgb(50,50,50), rgb(255,255,255), "Click me!", clickedCallback);" for every button gets old fast.

 

But seriously, if you want to finish a game, rolling your own commodity code is absolutely going to stop you from finishing.




#5029166 iOS Development on PC

Posted by smr on 05 February 2013 - 03:11 PM

There are a number of ways you can get *nearly* there with iOS development on Windows. You WILL, however, need a genuine Macintosh meeting the requirements of Apple, and also an Apple developer's license subscription to get your app on an actual device and into the app store.

 

* Unity (Free/Premium)

* MonoGame (Free)

* PhoneGap - JavaScript/HTML5/CSS3 (Free)

* MonoTouch (Premium)

* GameMaker Studio (Premium)

* Marmalade

 

I'm sure there are many more, but these are just the ones I've heard of.




#5027265 Career Changing into Game Industry?

Posted by smr on 30 January 2013 - 01:08 PM

I'm wondering if a good strategy for breaking in might be, if it's practical location-wise, to attend any and all game-develoment related meetups. IGDAhas information on these. Making friends with people in the industry might be a great way to get your foot in the door. I'm assuming you don't live in a very large metro area based on your salary, so it may be difficult to find these sorts of events, though.




#5022322 Pygame - Completely Removing a Sprite from Memory

Posted by smr on 16 January 2013 - 04:14 PM

Edit: I realized everything I said before was based on the assumption spellSprites is a list. It's not. It's a pygame sprite group. Sorry!

 

In any case, check to make sure you're not tucking away any references to these sprite instances anywhere else in your code. If you are, then this could be the source of your leak. As a diagnostic, call gc.collect() after your clean-up method. If the sprites are gone out of memory after a collection, then you could have created a circular reference somewhere between the sprite and some other object. Python uses reference counting to know when to clean up an object, but it also has a garbage collector that runs periodically that can recognize and collect objects lingering only due to circular references.




#5021451 Is creating an drawing class a good idea?

Posted by smr on 14 January 2013 - 10:51 AM

I'm not exactly sure how you're planning on using this, but yes, it's probably a bad idea.

 

If the goal of creating classes to represent my application is abstraction, then I probably don't want my game logic to have to think in terms of quads, but rather in Sprites or Models or Tiles or whatever it is that is actually being represented. That is of course unless you actually are just drawing quads to the screen...

 

In your renderer, you may want to treat quads as data and as items to perform calcualtions on, but you probably won't be drawing individual quads, as you'll be batching them and storing their indices in vertex lists and things like that which muddy up the definition of when a quad is actually "drawn."




#5017925 Javascript / HTML5 best practices

Posted by smr on 05 January 2013 - 05:16 PM

My general point was that the first and most important rule to writing efficient code is choosing the correct algorithm for the problem. I was generalizing in the case of quicksort vs bubble sort as you correctly assumed.




#5017511 Javascript / HTML5 best practices

Posted by smr on 04 January 2013 - 03:44 PM

First and foremost, since JavaScript is a programming language, the same general rules apply to writing efficient code:

  • Use the best algorithm for the task. Example, don't spend hours optimizing your bubble sort procedure when a quicksort will always be faster.
  • Use the features provided by the language's standard library, because they're probably written better than anything you'll create. Example, don't write your own quicksort. The standard library sort probably already does it.

Since javascript is a dynamic language, most of the same rules apply when optimizing:

  • Function calls to JavaScript are expensive. Calls to built-in functions may or may not be.
  • Dictionary references are expensive. Example: dictionary['thing']. If you need to access the same element more than once in a loop, assign it to a local variable before the loop then reference it with the variable.
  • Consider dictionary.thing to be equivalent to dictionary['thing'] as far as performance is concerned.
  • Functions are first class objects, and being first class objects they are no different than any other element in a dictionary on your objects: This line: "myobject.function()" can be considered the equivalent of "myobject['function']()" as far as efficiency goes. You can hoist this outside the loop too: 
    var myobject = new MyObject(whatever);
    var hoisted = myobject.function;
    
    for (var i = 0; i < 1000; ++i) {
        for (var j = 0; j < 1000; ++j) {
            hoisted(i, j);
        }
    }

     

     

  • "for (var i = 0; i < arrayLength; ++i)" is more efficient than "for (var i in array)" or even "for (var i = 0; i < array.length; ++i)" when the dictionary can be indexed sequentially.
  • Use built-in functions whenever possible, because they're often implemented in a low level language and compiled to machine code.
  • jsPerf is a great resource.
  • Don't optimize until you've profiled.
  • What is fast in Chrome might be slow in Safari, Firefox or Internet Explorer.



#5017288 Entity System

Posted by smr on 03 January 2013 - 05:00 PM

Right. Do what makes sense.

 

But I wonder what benefits there would be to implementing your UI elements as entities. I would think that UI elements are not a part of the game simulation, thus wouldn't be represented by entities within that simulation.

 

As far as your question about "traditional classes," component/entity systems /are/ traditional classes. They're just a specific way of organizing your relationships between classes. In my opinion if you implement OOP in the manner intended, most of your programs will tend to look like entity component systems in that you avoid deep hierarchies, keep classes small and single-purpose, etc.






PARTNERS