Search found 718 matches

by Sc4Freak
Mon Mar 12, 2012 1:55 pm UTC
Forum: Coding
Topic: On the Implementation of Entity-Component Systems
Replies: 32
Views: 20883

Re: On the Implementation of Entity-Component Systems

I just thought of something. Don't Entity-Component systems with external component managers sort of defile the corpse of the concept of encapsulation? Good programming involves hiding data, and the whole point of components only containing state and being managed elsewhere necessitates that data i...
by Sc4Freak
Fri Mar 09, 2012 6:11 am UTC
Forum: Coding
Topic: On the Implementation of Entity-Component Systems
Replies: 32
Views: 20883

Re: On the Implementation of Entity-Component Systems

Because it defeats one of the major strength of component systems: you minimise communication overheads and you can easily "batch" updates. Say you have a CollisionComponent that handles collision detection between components. Naive collision detection performs in O(n 2 ) time - simply che...
by Sc4Freak
Thu Mar 08, 2012 6:46 pm UTC
Forum: Coding
Topic: On the Implementation of Entity-Component Systems
Replies: 32
Views: 20883

Re: On the Implementation of Entity-Component Systems

An "entity" should be an actual object in your game world - like a player character, an enemy, a projectile, a powerup, etc. Things like UI elements don't fit into that. The idea behind components is that each entity should really be nothing more than a collection of components. Each compo...
by Sc4Freak
Wed Mar 07, 2012 5:14 am UTC
Forum: Coding
Topic: Output a String from a Subroutine
Replies: 44
Views: 9211

Re: Output a String from a Subroutine

You could also do something like: typedef struct { char string [20]; } string_return_type; string_return_type int_to_string (int i) { string_return_type r; sprintf (r.string, "%d", i); return r; } Stuffing it into a struct can get a fixed size string copied back to the caller's stack with...
by Sc4Freak
Tue Mar 06, 2012 6:22 pm UTC
Forum: Coding
Topic: of cross-platform threads and hate of libraries
Replies: 14
Views: 4414

Re: of cross-platform threads and hate of libraries

The std::thread class isn't coming out for a bit, and isn't yet available on MinGW. It should be pretty darn soon. C++11 has already been standardized. MSVC already ships with a complete C++11 standard library. I would expect Clang and GCC's implemenetations to come along fairly soon. Should I writ...
by Sc4Freak
Sun Mar 04, 2012 12:56 am UTC
Forum: Coding
Topic: Coding: Fleeting Thoughts
Replies: 9979
Views: 1975696

Re: Coding: Fleeting Thoughts

Visual Studio behaves similarly, except with even more allocation in the vector . (I don't know what its growth strategy is.) Visual Studio grows arrays by 1.5x each time it reallocates. Most implementations use 2x. It's still the same big-O complexity, of course, but MSVC's strategy trades reduced...
by Sc4Freak
Mon Feb 27, 2012 2:13 am UTC
Forum: Coding
Topic: Preferred Selenium 2.0 language
Replies: 3
Views: 1837

Re: Preferred Selenium 2.0 language

Whatever you're most familiar with, unless you have actual requirements that dictate a particular platform choice.
by Sc4Freak
Wed Feb 01, 2012 12:13 pm UTC
Forum: Coding
Topic: Infinite types in C#? (or maybe a better implementation)
Replies: 8
Views: 1979

Re: Infinite types in C#? (or maybe a better implementation)

For future reference, this is pattern is typically referred to as the "curiously recurring template pattern". It was originally a C++ pattern but applies equally well to C# generics. It the downside to this implementation is that I cannot currently work out a type T such that the following...
by Sc4Freak
Fri Jan 27, 2012 11:52 pm UTC
Forum: Coding
Topic: Renaming a class in C++
Replies: 15
Views: 4004

Re: Renaming a class in C++

Visual Assist X is the essential go-to plugin for C++ developers using Visual Studio. It can do exactly these sorts of things - smart renames and refactoring that are context-aware (rather than just a dumb regex search and replace). It's not free, unfortunately. EDIT: I just noticed that you already...
by Sc4Freak
Mon Jan 16, 2012 11:25 pm UTC
Forum: Coding
Topic: Help with arrays/multiple header files
Replies: 18
Views: 2486

Re: Help with arrays/multiple header files

I'm fairly certain you can't have an array of references. Arrays require default-constructible objects, and references can't be default constructed (since they can't be "reseated").
by Sc4Freak
Sun Jan 15, 2012 7:31 am UTC
Forum: Computer Science
Topic: Mind Blowing Algorithms
Replies: 76
Views: 28805

Re: Mind Blowing Algorithms

Something simple is C++'s next_permutation function. Without looking at the source I have no idea how it works. It's like black magic.
by Sc4Freak
Mon Jan 09, 2012 1:30 pm UTC
Forum: Coding
Topic: Terrain Rendering
Replies: 14
Views: 2879

Re: Terrain Rendering

You can see this in eg. Skyrim. As far as I can tell, they use a simple heightmap to define the shape of the "base" terrain, and custom-place models in the world when they want rocks, overhangs, or other complex features.
by Sc4Freak
Sat Jan 07, 2012 2:26 pm UTC
Forum: Computer Science
Topic: Ambiguous cases and Asimov's Three Laws of Robotics
Replies: 50
Views: 41253

Re: Ambiguous cases and Asimov's Three Laws of Robotics

For those unaware, it may be worth pointing out that a large proportion of Asimov's Robot books were exactly about interpretations of the Three Laws and how they could be "broken".
by Sc4Freak
Wed Dec 21, 2011 7:57 am UTC
Forum: Individual XKCD Comic Threads
Topic: 0993: "Brand Awareness"
Replies: 232
Views: 68340

Re: 0993: "Brand Awareness"

As an Australian I was confused by this comic as well. "So... he wants Home Brand products?" :P
by Sc4Freak
Sat Dec 17, 2011 10:50 am UTC
Forum: Coding
Topic: Why should I use get and set for my class methods?
Replies: 14
Views: 4209

Re: Why should I use get and set for my class methods?

The reason for using getters and setters is encapsulation. They protect clients of the class from changes in the internal implementation. You might want to add some debug checking whenever someone gets the width of a video, for example. Or you might want to enforce an invariant that width == height ...
by Sc4Freak
Thu Dec 08, 2011 11:31 pm UTC
Forum: Coding
Topic: Odd design decisions?
Replies: 55
Views: 8291

Re: Odd design decisions?

This might be Windows-API-specific, but surely I'm not the only one who gets annoyed with the various "secure", "fixed", and "final, no, really, we mean it this time" versions of standard library functions which are now deprecated. "Oh, you shouldn't be using spri...
by Sc4Freak
Sat Nov 26, 2011 10:27 pm UTC
Forum: Coding
Topic: Simple Iterator Adaptor for Upcast (C++)
Replies: 2
Views: 1696

Re: Simple Iterator Adaptor for Upcast (C++)

An alternative solution is to use a templated base. i.e. #include <vector> #include <iostream> struct DataBase { int sharedData; virtual const char* Foo() const = 0; DataBase(int x) : sharedData(x) {} }; struct DataDerivedA : public DataBase { virtual const char* Foo() const { return "DataDeriv...
by Sc4Freak
Sat Nov 26, 2011 10:22 pm UTC
Forum: Coding
Topic: [C#][XNA] Templated Functions and Game Components
Replies: 3
Views: 1402

Re: [C#][XNA] Templated Functions and Game Components

Well firstly, it can't find the classes "Game1.Planet" and "Game1.Probe". I'm guessing that Game1 is a class - make sure the classes Planet and Probe actually do exist in the class Game 1 and that they are specified public. Secondly, a Component is probably a bit overkill. In XNA...
by Sc4Freak
Mon Nov 21, 2011 10:00 pm UTC
Forum: Individual XKCD Comic Threads
Topic: 0980: "Money"
Replies: 375
Views: 105489

Re: 0980: "Money"

I hope Randall doesn't mind, but I've uploaded the image to zoom.it for easier viewing.

http://zoom.it/oYhg

Uses HTML5 and much easier to use.
by Sc4Freak
Thu Nov 17, 2011 12:47 am UTC
Forum: Coding
Topic: Coding: Fleeting Thoughts
Replies: 9979
Views: 1975696

Re: Coding: Fleeting Thoughts

I dunno, I've seen that "trick" everywhere and IMO if it's blindingly obvious that the cast can never fail, using "as" is okay.

eg.

Code: Select all

if(sender is TextBlock)
{
    (sender as TextBlock).Text = "Hello, world!";
}
by Sc4Freak
Thu Nov 17, 2011 12:44 am UTC
Forum: Coding
Topic: Throwing a templated exception (C++)
Replies: 11
Views: 1931

Re: Throwing a templated exception (C++)

Compiles in Visual Studio 2010 as well. But VS2010 doesn't support exception specifications at all, and never will (except for nothrow or the empty exception specification). Exception specifications have been deprecated in C++11 and you shouldn't be using them.
by Sc4Freak
Wed Nov 09, 2011 6:30 am UTC
Forum: Coding
Topic: use of __declspec(noinline)
Replies: 17
Views: 5087

Re: use of __declspec(noinline)

Ah, I just tried it for myself and you're right. It still surprises me, though, because really it still seems to me that MSVC should be able to handle that. Not sure why it doesn't.
by Sc4Freak
Tue Nov 08, 2011 7:13 am UTC
Forum: Coding
Topic: use of __declspec(noinline)
Replies: 17
Views: 5087

Re: use of __declspec(noinline)

I think I would call it a bug actually, since inline is supposed to be a hint. As such, the compiler has the option to _not_ inline it, and as such, should not fail to compile valid code because it's ignoring options available to it. Even worse, there is no standard way to write the function withou...
by Sc4Freak
Tue Nov 08, 2011 12:33 am UTC
Forum: Coding
Topic: use of __declspec(noinline)
Replies: 17
Views: 5087

Re: use of __declspec(noinline)

I'm not sure if I'd call this a bug in MSVC. First you need to consider how many executions of not_quite_recursive are going to happen. On each call to not_quite_recursive, you call not_quite_recursive twice more up to a maximum depth of 100. On the first call, it branches out twice. Each of those t...
by Sc4Freak
Tue Oct 11, 2011 8:44 am UTC
Forum: Coding
Topic: Odd design decisions?
Replies: 55
Views: 8291

Re: Odd design decisions?

D:

I remember reading that page years ago when I was getting up to speed with C++. Small world.
by Sc4Freak
Sun Oct 09, 2011 11:03 am UTC
Forum: Coding
Topic: C# Priority Queue/Heap
Replies: 2
Views: 5323

Re: C# Priority Queue/Heap

You can use a plain old List . The BinarySearch method does everything you need it to - give it an object, and it'll return the index of that object (performing a binary search through a sorted list). If the object doesn't exist, it'll return the bitwise complement of the index where the object shou...
by Sc4Freak
Fri Oct 07, 2011 11:02 am UTC
Forum: Coding
Topic: C Preprocessor Macros
Replies: 16
Views: 8591

Re: C Preprocessor Macros

And if you're feeling adventurous and have a compiler that supports variadic templates and r-value references, you can implement the first macro as a function too.
by Sc4Freak
Tue Oct 04, 2011 11:23 am UTC
Forum: Coding
Topic: Odd design decisions?
Replies: 55
Views: 8291

Re: Odd design decisions?

Actually, there aren't that many oddities in C++ if you ask me. Plenty of gotchas, but C++'s gotchas are typically there for a reason - they're usually not just oversights. I think C++ is pretty well designed, and it definitely feels like a language that was engineered from the ground up whereas som...
by Sc4Freak
Thu Sep 22, 2011 7:02 am UTC
Forum: Coding
Topic: WINDOWS: Let's say I have a *bunch* of files in one folder
Replies: 20
Views: 3199

Re: WINDOWS: Let's say I have a *bunch* of files in one fold

I've had awful experiences with CDs. They seem to degrade eventually - my CD backups from ~2001 are all dead. I no longer trust CDs, and I view DVDs with a similar suspicion. I know there exist DVDs which have a special "long lifetime" designed for backups, but they're expensive and there'...
by Sc4Freak
Tue Sep 20, 2011 8:42 am UTC
Forum: Coding
Topic: Pre-emptive Copy
Replies: 18
Views: 3122

Re: Pre-emptive Copy

I was just about to say exactly what Xeio said. A more sane solution to your problem would be to use language features and/or your IDE to do this kind of work for you rather inventing hacks to do it yourself.
by Sc4Freak
Wed Sep 14, 2011 7:02 am UTC
Forum: Coding
Topic: Is there an alternative to this try/catch block?
Replies: 20
Views: 4867

Re: Is there an alternative to this try/catch block?

In C#, this is achieved with a "using" block:

Code: Select all

using (var stream = new FileStream("text.txt"))
{
    // do stuff
} // the stream is automatically disposed
by Sc4Freak
Wed Sep 14, 2011 2:38 am UTC
Forum: Coding
Topic: Coding: Fleeting Thoughts
Replies: 9979
Views: 1975696

Re: Coding: Fleeting Thoughts

by Sc4Freak
Mon Sep 12, 2011 12:54 am UTC
Forum: Coding
Topic: Is there an alternative to this try/catch block?
Replies: 20
Views: 4867

Re: Is there an alternative to this try/catch block?

For an unrecoverable error, use an exception. That's what they're there for. If your constructor fails, for example, you should throw an exception rather than use a "valid bit". The purpose of a constructor is to build an object out of dust so that it satisfies its invariants. If the const...
by Sc4Freak
Fri Sep 09, 2011 1:56 am UTC
Forum: Coding
Topic: Help with a project
Replies: 8
Views: 2374

Re: Help with a project

Another note on coding standards: the style adopted by the C++ standard library is due to historical legacy more than anything else. In most other languages (Python, Java, C#, etc) there is a single canonical style that practically everyone follows. That's not the case in C (and even less so in C++)...
by Sc4Freak
Fri Jun 24, 2011 10:58 pm UTC
Forum: Coding
Topic: hack copy
Replies: 4
Views: 1070

Re: hack copy

Why do you need to construct a new LinkedVector? Why not juse use list.resize()?
by Sc4Freak
Thu Jun 09, 2011 4:25 am UTC
Forum: Coding
Topic: Coding: Fleeting Thoughts
Replies: 9979
Views: 1975696

Re: Coding: Fleeting Thoughts

EvanED wrote:While I definitely cringe at the thought of writing applications in JavaScript, it's also not the worst language out there by any means...

You're right, Javascript is probably second to PHP in terms of painfulness. :P
by Sc4Freak
Thu Jun 09, 2011 12:33 am UTC
Forum: Coding
Topic: Coding: Fleeting Thoughts
Replies: 9979
Views: 1975696

Re: Coding: Fleeting Thoughts

Javascript efficiency has been increasing dramatically thanks to the second browser wars. Current browsers actually compile Javascript code to native code. A simple loop (tested using this ) on Opera 11.10 seems to run about 100 times faster than in Python 2.7.1. If this trend continues, we might h...
by Sc4Freak
Thu Jun 02, 2011 9:17 am UTC
Forum: Coding
Topic: new to coding: should I use Visual Studio?
Replies: 7
Views: 1834

Re: new to coding: should I use Visual Studio?

In terms of IDE, VS is generally regarded to be one of the best. So if you're having trouble with learning how to program, moving to a different IDE probably won't help. C# is a fairly intermediate language in terms of difficulty, if C++ is "hard" and Python or BASIC is "easy". A...
by Sc4Freak
Thu May 26, 2011 5:44 am UTC
Forum: Coding
Topic: c++ closures
Replies: 15
Views: 2964

Re: c++ closures

Modern C++ usually doesn't have much manual memory management in it. Every new[] should be replaced with vector (or deque) and every new should be immediately given to a smart pointer. In an ideal C++ program it should be pretty rare to see a delete statement.
by Sc4Freak
Sun May 22, 2011 3:28 am UTC
Forum: Coding
Topic: Coding: Fleeting Thoughts
Replies: 9979
Views: 1975696

Re: Coding: Fleeting Thoughts

Don't. Smart pointers are extremely difficult to write correctly. tr1 or Boost, it doesn't matter so long as you're not writing your own! Off the top of my head: ⋅  You don't provide const overloads, so you won't be able to use it as a const object ⋅  You don't provide any cast o...

Go to advanced search