Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length

 
Advanced search

1074034 Posts in 44030 Topics- by 36032 Members - Latest Member: jwar

December 21, 2014, 06:45:51 PM
  Show Posts
Pages: 1 [2] 3 4 ... 67
21  Developer / Technical / Re: Conditional compilation in Java? on: August 19, 2014, 05:38:02 PM
There's no reason why you can't just use a C preprocessor on your Java files.
22  Developer / Technical / Re: C# Equals Documentation Question on: July 31, 2014, 04:36:37 AM
I don't do C#, but if the examples of it on MSDN are anything like the C++ examples there, they're generally awful and should always be looked at with suspicion.
23  Developer / Technical / Re: learning c++ on: July 25, 2014, 03:54:09 PM
Be wary of any books or tutorials that you find that are more than a couple years old.  There a lot of things that were considered good practice before C++11 that are now bad ideas.

If there's one thing to understand about C++, it's that it's a value semantics language.  A lot of people try to write C++ as if it were Java or C# and that never works well.  Modern C++ rarely uses pointers or dynamic objects, with the new C++11 rvalue references the need for dynamic memory (and hence, the possibility of memory leaks) should be fairly rare.  This is a fairly advanced topic though, so make sure you make all the usual mistakes along the way first, then you'll understand it.

The object-oriented stuff is fine and dandy, but modern C++ is really about generic programming, what C++ calls templates.  Object-oriented C++ is sort of old hat these days.  It will never go away, but generic programming is where the action is.  Unfortunately, it can take a long time to truly grasp the things that can be done, so don't worry if you don't get it right away, plenty of other people don't either.
24  Developer / Technical / Re: What's your favorite programming language? on: July 13, 2014, 09:48:07 AM
Ada.  It's what C++ would be without all the C baggage.
25  Developer / Technical / Enum extensions for C++ 2011 on: June 18, 2014, 06:59:55 PM
I use enums a lot, in pretty much every language I code in.  My favorite enums happen to be in my favorite language, Ada.

I recently started a C++2011 project, and quickly began wishing I could do some of the things with C++ enums that I could do with Ada enums.  I've often said that one of the great things about C++ is that whatever the language doesn't support can usually be faked with templates.  I decided to whip up some easy to use enum extensions to get a handle on some of the new metaprogramming facilities in C++2011.

There were two big things I wanted to accomplish:

Enum iteration

Ada's for loop allows you to iterate through an entire (scalar) type.  Getting C++ to iterate through all values of an enum is a pain, especially if you assign unusual numeric values to the enum members.  Also, Ada can run this loop in both directions.  I was saddened to see that C++2011's new ranged for loop doesn't allow reverse iteration, I expect C++2014 will provide a library adapter for this, std::reverse or something.

String based IO

Ada enums are input and output as strings, not numbers.  I greatly prefer this to what C++ does, it's a huge aid in debugging and makes files containing enum output a whole lot easier to parse visually.

Here's a quick Ada snippet demonstrating these concepts:

Code:
bash-4.3$ cat enum_demo.adb
with Ada.Text_IO;

procedure Enum_Demo is
    -- This is an enumeration.
    type Day is (Mon, Tue, Wed, Thu, Fri, Sat, Sun);

    -- Enum IO instantiation.
    package Day_IO is new Ada.Text_IO.Enumeration_IO(Day);
begin
    -- Iterate through all values, printing them out.
    Ada.Text_IO.Put_Line("Enum forward:");

    for X in Day loop
        Day_IO.Put(X);
        Ada.Text_IO.Put(' ');
    end loop;

    Ada.Text_IO.New_Line;

    -- Do the same in reverse.
    Ada.Text_IO.Put_Line("Enum reverse:");

    for X in reverse Day loop
        Day_IO.Put(X);
        Ada.Text_IO.Put(' ');
    end loop;

    Ada.Text_IO.New_Line;
end Enum_Demo;

bash-4.3$ enum_demo
Enum forward:
MON TUE WED THU FRI SAT SUN
Enum reverse:
SUN SAT FRI THU WED TUE MON
bash-4.3$

With the help of some macros and a plethora of templates, I managed to reimplement these facilities in C++.  They do require the coder to provide some data, specifically the enum table and the strings that you want to use for IO.  Here's a demo of what I came up with:

Code:
bash-4.3$ cat main.cpp
#include "enum_range.h"
#include "enum_io.h"
#include <iostream>

namespace NS
{
    // Enum class with range and IO.
    enum class Day {mon, tue, wed, thu, fri, sat, sun};
    // Enum with range, but not IO.
    enum Weekday {mon, tue, wed, thu, fri};

    class Calendar
    {
    public:
        static
        void print();

    private:
        // Private nested enum with values.
        enum Weekend {sat = 6, sun = 7};

        // Friendship required.
        DECLARE_ENUM_RANGE_FRIEND(Weekend);
    };

    // Bring the operator into the enum namespace for ADL.
    using EnumIO::operator <<;
}

// Declare the range for the enum class.
// A range declaration is required for the IO system.
// These macros must be placed in the global namespace.
DECLARE_ENUM_RANGE(NS::Day, NS::Day::mon,
                            NS::Day::tue,
                            NS::Day::wed,
                            NS::Day::thu,
                            NS::Day::fri,
                            NS::Day::sat,
                            NS::Day::sun);
// Range for the plain enum.
DECLARE_ENUM_RANGE(NS::Weekday,
                   NS::mon,
                   NS::tue,
                   NS::wed,
                   NS::thu,
                   NS::fri);
// Range for the nested enum.
DECLARE_ENUM_RANGE(NS::Calendar::Weekend, NS::Calendar::sat, NS::Calendar::sun);

// IO string definitons for the enum class and nested enum.
DECLARE_ENUM_IO(NS::Day, "mon", "tue", "wed", "thu", "fri", "sat", "sun");
DECLARE_ENUM_IO(NS::Calendar::Weekend, "sat", "sun");

void NS::Calendar::print()
{
    // Print the nested enum values going forward.
    std::cout << std::endl << "nested enum with values:" << std::endl;

    for (Weekend we : EnumRange::forward<Weekend>())
    {
        std::cout << we << ' ';
    }

    std::cout << std::endl;
}

int main()
{
    // Print out all days going forward.
    std::cout << "enum class forward:" << std::endl;

    for (NS::Day d : EnumRange::forward<NS::Day>())
    {
        std::cout << d << ' ';
    }

    // Do the same going backward.
    std::cout << std::endl << "enum class reverse:" << std::endl;

    for (NS::Day d : EnumRange::reverse<NS::Day>())
    {
        std::cout << d << ' ';
    }

    // Weekdays going forward, uses ordinary numeric IO.
    std::cout << std::endl << "enum forward, no strings:" << std::endl;

    for (NS::Weekday wd : EnumRange::forward<NS::Weekday>())
    {
        std::cout << wd << ' ';
    }

    NS::Calendar::print();
}

bash-4.3$ a.out
enum class forward:
mon tue wed thu fri sat sun
enum class reverse:
sun sat fri thu wed tue mon
enum forward, no strings:
0 1 2 3 4
nested enum with values:
sat sun
bash-4.3$


There are three macros that make all this possible.

DECLARE_ENUM_RANGE creates the enum range.  You simply give it the enum type, and a list of all its values.  This will allow the use of the functions EnumRange::forward<Type>() and EnumRange::reverse<Type>() to iterate the enum in either direction.

DECLARE_ENUM_IO builds the string table for the stream operators.  A range for this enum must have already been declared before the use of this macro.  A helpful static_assert will tell you when you screw this up.

DECLARE_ENUM_RANGE_FRIEND inserts necessary friend declarations to allow access to nested private enums.

The first two macros MUST be used at global scope.  The code they produce is in the EnumRange and EnumIO namespaces, so don't worry about namespace pollution.

Also, the EnumIO operators << and >> must be brought into the namespace that the enum lives in.  A simple using directive will accomplish this.

These examples don't demonstrate input, but it works the same way.

The range code is constexpr to the maximum extent I could pull off, so the compiler could optimize range iteration to near zero runtime overhead.  There is a small space overhead for the value table, but that's a constexpr std::array, so you don't get much smaller than that.

The IO code is also pretty streamlined, the only real work is in the << and >> operators.  The only space overhead is the string table, once again a constexpr std::array.

The EnumRange and EnumIO namespaces also include traits testers, HasRange and HasTraits.  These are used in the implementation, but can also be used for general metaprogramming purposes.

Sadly, the one thing I couldn't accomplish was applying these features to a enum declared locally in a function body.

If anyone things this stuff is neat and wants to use it, feel free to nab the two headers here.
26  Developer / Technical / Re: Scrolling games that scroll poorly on: May 26, 2014, 03:26:10 PM
I think a lot of games would do themselves a world of good by only supporting fullscreen (I never understood the trend of gaming in a tiny window), setting the refresh-rate themselves, and if the game slows down, too bad. Most indie games have absolutely no excuse for dropping below 60fps on any semi-modern computer.

I prefer playing games in a window more often than not.

I think developers should stop trying to force console paradigms onto PCs.  PCs are a totally different world, and there's so much more you can take advantage of.  Take the time to allow the user to run your game the way they want to.  If the player wants to run my game in a 20x30 window at 4 FPS, that's their business.
27  Developer / Technical / Re: Scrolling games that scroll poorly on: May 26, 2014, 06:59:39 AM
Fixed timesteps are the way to go unless determinism doesn't matter (which is almost never).

There are a lot of games in which determinism really doesn't matter.  Anything turn-based, for example.
28  Developer / Technical / Re: How to proceed with a multiplayer game, first the game or first the net code? on: April 27, 2014, 07:49:39 AM
It's generally easiest to not even differentiate between single player and multiplayer.  "Single player" works identically to any other situation, it just talks to a local server.
29  Developer / Technical / Re: Creating a new programming language from scratch? on: April 12, 2014, 09:55:35 AM
Thanks for the recommendation Cheesegrater, I'll look into that. Is that book more regarding theory of compilers, or is is based around an actual compiler that is dissected and studied in-depth?

In practice, the theory is nearly impossible to separate from the implementation, unless you're writing a bad compiler, I guess.

Also, if its not proprietary information, would you mind if take a look over your own created language, and maybe clue me in to important lessons you had to learn the hard away?

It's not far enough along to have anything to show, just notes and stuff in my head, really.  However, one of my current game projects has its own simple scripting language.  It's not a "programming language" in any real sense, but the code does have a complete parser and tokenizer.  It's all GPL, so feel free to look at it.  Source is included in all the downloads.
30  Developer / Technical / Re: Creating a new programming language from scratch? on: April 11, 2014, 05:23:44 PM
I've written compilers for college, and I've also been dabbling in a language of my own design for many years (all generic, all the time!).

Compilers are, as has been pointed out, not trivial to write, and languages are much harder to design than you might expect.  One thing to consider is that compilers can generally be broken down into semi-independant parts and you may want to start be learning how to write some of those smaller parts.

In particular, knowing how to write a general language parser is immensely valuable.  I can't think of a single significant project that I've worked on that didn't involve writing a language parser at some point.
31  Developer / Technical / Re: Simple cross-platform gamepad library on: April 01, 2014, 06:54:57 PM
Yeah, figured it was a bad assumption. Without that it makes menu navigation to get to the controller mapping require a keyboard which is not ideal but meh I suppose.

This is why I insist on making controller configuration mouse driven, preferably in a configuration program external to the game.
32  Developer / Technical / Re: Simple cross-platform gamepad library on: April 01, 2014, 06:31:19 PM
Yeah, we mapped that one a bit back and thought it was interesting. That one has no ill effects for us though, unlike my external webcam which registers as a multiaxis controller and generates axis 0 and axis 1 data for no apparent reason. Based on our mappings every controller has reported axis 0/1 as left stick - is this a universal truth or a bad assumption (and yeah, there is 0 consistency for any other stick/triggers/buttons.)

I think my flightstick reports the throttle as axis 0 and the stick as 1/2, but I would have to check.

Either way, I wouldn't make any assumptions at all about what's what,
33  Feedback / DevLogs / Re: Ratcatcher on: March 22, 2014, 10:01:41 AM
It's been a long time since I've updated this, but work has been slowly creeping forward.

I've mostly been working on controller code, and I believe I have it sorted out across all four main platforms.  The Haiku stuff is a little sketchy, my pads seem to work for a bit and then just stop.  Being that it's an alpha quality OS, I'm not sure where the problem is.  Some of my previous Haiku work has run into OS bugs, so I can't really rule that out.

I've also started an Atari 5200 version.  Making an Atari game was a childhood dream of mine, so I decided to finally make it come true.  The 5200 version isn't nearly as far along as the others, I'm still learning the hardware and getting the playfield assembled.  Here's an early screenshot:



The coloration is a bit weird since I'm still playing with different color patterns and stuff.

I've also implemented a replay system in the main platforms, games can be saved and played back.  Of course, the game is in such an early state that replays can't be guaranteed to work in the future.

I've uploaded current builds if anyone wants to play around with them.  All PC builds include the complete source code, GPL3 licensed.  The 5200 ROM doesn't include source, but the source for that is with the other builds.  The Haiku build has some directory issues that I still have to solve, and should be launched from a command line.

Linux x86
Linux x64
Windows
Mac
Haiku
Atari 5200
34  Developer / Technical / Re: Textures, atlases, and in between on: March 22, 2014, 08:30:57 AM
Quote
Yeah, this is actually a really big optimization.  My most recent large gains in performance have come from reducing binding calls
Fascinating! What are the numbers? How much did you gain simply by minimizing binding calls?

It was several months ago, so I don't recall the exact numbers, but I remember it being in the neighborhood of a 10-15% gain in performance.

Quote
take a look at texture arrays - they're a way more elegant solution
What are they? How do they work? Which GL version are they introduced in?

Textures arrays are a variant of 3D textures that let you bind a collection of 2D textures in one shot.  I believe they were introduced somewhere in OpenGL 3.
35  Developer / Technical / Re: Textures, atlases, and in between on: March 22, 2014, 07:49:49 AM
"Less binding textures. Pretty lame optimization" - Not that lame IMO, it's not so much binding fewer textures, it's being able to issue fewer draw calls, which is very important if you're trying to push the most out of your platform.

Yeah, this is actually a really big optimization.  My most recent large gains in performance have come from reducing binding calls, not just textures, but VBOs, shaders, etc...
36  Developer / Technical / Re: Programming languages + rewrite on: March 21, 2014, 06:09:51 PM
Speaking from recent experience, rewriting your game in another language is a demoralizing and frustrating process.

Really?  I actually find it fascinating and enjoyable, but maybe that's just me.
37  Developer / Technical / Re: Realism in Renderings on: March 19, 2014, 06:46:31 PM
Define realism.
38  Developer / Technical / Re: Compiler Linking Help on: March 13, 2014, 04:08:31 AM
That's not a big project.  I'm talking about stuff I once heard lovingly called "IBM big."
39  Developer / Technical / Re: Compiler Linking Help on: March 12, 2014, 08:05:13 PM
The 'correct' way to handle multi-platform development, however, is to use something like cmake (there are plenty of alternatives, though), and use it to generate Makefiles, IDE projects, etc automatically.

"Correct" or not, it's not as hard as you might think to write a Makefile that works on all platforms you target. It's how I do all of my work, and my toolchain is basically identical to 0x1dea's. Vastly better workflow than any IDE I've ever used.

Yes, once you get beyond a certain experience level, IDEs hurt more than they help.

I've been in software development professionally for almost 10 years now, and you can pretty consistently identify the developers who know what they're doing if you look for the ones not using IDEs.

It's also worth mentioning that when project reaches a certain size, most IDE features become essentially unusable.  Granted, most projects on this site will never reach that size, but I've worked on a couple big projects that had.

Dropping IDEs and going to vim+make was one of the best things I've ever done.
40  Developer / Technical / Re: Programming turn based system like in Frozen Synapse on: March 10, 2014, 05:19:23 PM
Hi guys. I am currently trying to make a small game, but am having trouble trying to figure out some of the programming logic. Basically, I am trying to have a turn based system like in frozen synapse. How would you program the timing system? I've only ever worked on real time games, so this is a bit foreign to me.

I would assume that you need to store the initial variables of the entities (position, velocity, etc), and when going forward in time, you simulate the physics multiplied by the time you want to display. Is there anything else you think I need to keep in consideration?

Not everyone has played the game you're referring to.  It would help if you would describe your problem in more detail.  I could probably answer your question, but I have no idea what you're talking about.
Pages: 1 [2] 3 4 ... 67
Theme orange-lt created by panic