Jump to content

  • Log In with Google      Sign In   
  • Create Account

Pink Horror

Member Since 02 Jul 2013
Offline Last Active Yesterday, 06:33 PM

#5297062 Microsoft Checked C

Posted by Pink Horror on 17 June 2016 - 07:54 PM


It also most definitely does not include anything even close to weak_ptr.

Are you sure? When reading it through, it looked like ptr<T> was designed to NULL out when the original data was invalid. That is the functionality from std::weak_ptr<T> that would be very nice.

No. This doesn't solve anywhere near enough real problems compared to just using modern C++.

C++ can't solve this issue because it itself is based upon potentially dangerous C libraries. As a library consumer, C++ (even Java and C#) seem better than C but remembering that underneath all their hoods, the same dangers can (and almost certainly do) still lurk, it removes all the fun ;). Plus these languages end up running more C than a C program due to their additional layers written in C so they are still not ideal.

Checked C aims to remove these issues at a much lower level than possible by just bolting on another random language.


The paper says it is about bounds-checking. a weak_ptr has nothing to do with bounds checking. The introduction is entirely about bounds-checking. It mentions problems such as using already-deleted memory are beyond the scope of Checked C.

C++ can at least partially solve the issue, because you can use templates to create the checked pointer classes. That's what the team who made this did as a prototype.

Just building with Checked C instead of C gets you nothing. You have to use the new types. Converting one of those potentially dangerous libraries to Checked C means putting in the correct changes to use bounds-checking everywhere they would belong, and making no mistakes or oversights while doing so. As long as you're rewriting chunks of the library, why not rewrite them in C++? What's the difference? How does the library go from potentially dangerous to knowing it's safe? How do you know you did the conversion correctly? How do you know the library isn't dangerous because of something that wasn't covered, like memory allocation?

If, for some reason, you have a code base that's in C, and you're willing to rewrite every part of it that uses pointers, and compiling it in C++ scares you and/or you're not willing to create the helper templates yourself, but compiling it in a new version of C from Microsoft is something you're willing to do, and you're having trouble with buffer overflows, and compile-time checks will help or run-time crashing is ok, than sure, Checked C might solve a problem for you.

#5296040 Need some advice or direction on a Mod friendly data structure.

Posted by Pink Horror on 10 June 2016 - 08:29 PM

Large databases with around 40TB of data presently.


You mention a millisecond.


Kept in local memory lookup, that is on the order of tens of nanoseconds.


Use the nanosecond-speed one when possible.

So, you're saying that Tangletail's game's DB performance will be similar to a 40TB database, and that one frame of a typical  video game happens in tens of nanoseconds?

#5295894 Need some advice or direction on a Mod friendly data structure.

Posted by Pink Horror on 09 June 2016 - 07:54 PM

Big relational databases work well for persistence, but realize that queries are time consuming. Even fast queries to an RDBMS take longer than most video game frames. If you're storing a lot of data and reading it as part of loading a character or map or level it can work, but they are a poor choice for this type of data.

I don't know what database you're using, but on the servers I typically work with, the complete round-trip time of sending a simple, plain-text SQL query over the network to another server, processing it, and getting the result back often takes less than one millisecond. I'm sure a game could do it even faster with a local, in-memory database. And actually, I know that's true, because I've also worked on a game that did that.

#5295566 use ID or Pointers

Posted by Pink Horror on 07 June 2016 - 08:37 PM


Add "no type-safety" to the "cons" list for integer handles/IDs, please.

You can add integer ID's (and void* ID's!) to the C++ type system like this, in order to maintain type safety:
struct PrimitiveBase {};
template<class T, class Name> struct PrimitiveType : PrimitiveBase
	typedef T Type;
	PrimitiveType() : value() {}
	explicit PrimitiveType(T v) : value(v) {}
	operator const T&() const { return value; }
	operator       T&()       { return value; }
	T value;

#define MAKE_PRIMITIVE_U64(name)					struct tag_##name; typedef PrimitiveType<u64,tag_##name> name;
#define MAKE_PRIMITIVE_U32(name)					struct tag_##name; typedef PrimitiveType<u32,tag_##name> name;
#define MAKE_PRIMITIVE_U16(name)					struct tag_##name; typedef PrimitiveType<u16,tag_##name> name;
#define MAKE_PRIMITIVE_S16(name)					struct tag_##name; typedef PrimitiveType<s16,tag_##name> name;
#define MAKE_PRIMITIVE_U8(name)						struct tag_##name; typedef PrimitiveType<u8,tag_##name> name;
#define MAKE_PRIMITIVE_S8(name)						struct tag_##name; typedef PrimitiveType<s8,tag_##name> name;
#define MAKE_PRIMITIVE_PTR(name)					struct tag_##name; typedef tag_##name* name;
class Foo
  MyObjectId Create();
  void Release( MyObjectId );

What does PrimitiveBase do for you in this case?

#5294384 responsiveness of main game loop designs

Posted by Pink Horror on 31 May 2016 - 06:46 PM

>> I'm pretty sure he was joking.... 


see, things are so whacked in game development i couldn't even tell!   i've seen some really crazy and stupid sh*t come down the pike over the years.  i used to think its was only regular software development that was full of idiots.  time has proven otherwise.

So I'm an idiot, eh? Oh well, I don't really suppose I could prove otherwise.


i later realized what hodgeman meant. they poll at 5 hz and update for 200ms, so the player still gets a fair share timeslice. physics runs at faster speeds, similar to stepped movement for projectiles, for greater accuracy, but the overall timeslice length is the same (i assume).


He's saying HUMANS act at 5 Hz. He's not suggesting that means a game should poll input devices at 5 Hz.

#5294208 Do you usually prefix your classes with the letter 'C' or something e...

Posted by Pink Horror on 30 May 2016 - 01:04 PM


Sure sure... it's just worthless information encoded in to a name which a human is reading... and just wait until you need a 'ThingClassClass'... or when you decide it is no longer a class.. or something becomes a class...

Or a type for a classification of a group of students; a ClassClassClass? :lol:


That does sound like it might be a little ambiguous. Maybe the naming should be more like:







I make variable names like this for real when I have to make something as a workaround:

std::string copyBecauseFuncIsntConstCorrect = str;

#5294205 How to set a namespace properly in this case?

Posted by Pink Horror on 30 May 2016 - 12:52 PM


I don't want to create a library yet since my code is still changing, but I do plan on doing that once it settles. I just wanted to know how to reference the base code. It's ok I'm looking it up right now though. Thank you for pointing me in the right direction.


A static library doesn't require having anything close to a settled interface to it. It's just a collection of compiled code bundled up into a file. If you're working in Visual Studio, you barely even notice it is separate.

Even when just starting out, it can be useful to keep the majority of your code in a library. That allows it to be linked against the main executable and any other secondary executables, such as unit tests, easily.

Your general problem is that you want to share one file with the WinMain stuff among several other projects you're working on, right?

I don't really think there's going to be a way to do this - to have one main file that links in different other files depending on what you're in the mood to do - that feels clean. It's going to be a little hacky one way or another. So here's one really hacky idea:

In Visual Studio you can have multiple projects under one solution. There's nothing stopping multiple projects from sharing the same files. So, you give each game its own project. You should make sure each project puts its build artifacts in different places using project properties. Then, you still have to choose which code gets used by the main file. You've mentioned a "using namespace" line. That should work. Just make it "using namespace GAME_NAMESPACE". In the properties for each project, define the GAME_NAMESPACE macro to be the correct namespace for that project.

Now, I must point out, it's not really ideal to have the same files built multiple times for different projects. That's where the static libraries come in. If you have some code shared by all your games, that can go into a library project and be built once. Then it doesn't have to be rebuilt just because you switch. This can save you some time if you change some code in the library, and you want to make sure all of your games build at once. Also, if there's a compile error in a source file that is shared between projects, it'll be repeated in every project you build. That's just annoying. Libraries are easy enough to make to be worth it just to avoid that nonsense.

I should also point out that you don't want to get carried away with this. Source code included in multiple projects, compiling with different macros in each one, can quickly become a confusing mess. Visual Studio doesn't know what to do with it when you browse the file. If you're lucky, Intellisense will at least be based off just one project, not a mix. It's much more annoying than just multiple compile errors. I worked for a company that did something like this. That project was a buggy disaster.

It's probably a better idea to break down your main file into shareable functions as much as possible, and then copy-and-paste the rest. It shouldn't be a file that is revisited much. If you do find yourself making the same edit to several of these main files in different projects, use that as a opportunity to extract more shared code.

#5294201 Recent Graduate Looking For Advice

Posted by Pink Horror on 30 May 2016 - 12:28 PM

Have you tried searching for game programming jobs? Do you know any studios where you want to work?

I could just be old-fashioned and bad at networking, but I thought business cards are for people who have a job already. Maybe I could have done better, but I've managed to find work without ever making my own business cards, writing a blog, going to a career fair, or participating in any game nights/jams. I did make a portfolio when I first started out. It was really, really bad.

I looked at your web site. There's one obvious thing missing: programming. You want a game programming job, right? You mention a little about Unity programming, and there may be more buried in an actual article somewhere, but on the surface, you're presenting yourself as a game designer and artist. It's good to be enthusiastic about games and design as a programmer, but it's better to demonstrate that you actually want to do some programming, and that you know how to program.

#5293966 responsiveness of main game loop designs

Posted by Pink Horror on 28 May 2016 - 02:51 PM

just cause you can only draw the screen once every 8 games turns doesn't mean you should let the computer move every turn and only let the user move every 8 game turns.

There should also get to be one human player for every core involved, or else the computer is ganging up on the player.

#5293137 Wrapper Function for lua_register?

Posted by Pink Horror on 23 May 2016 - 07:04 PM

Lua is written in C and thus cannot interact interact with C++ (there is no well-defined C++ ABI and as such 'calling a member function' is an unsolvable problem because different C++ compilers have very different idea what exactly that means and how to do that).

Lua is written to be capable of building in C or C++, and it is distributed as source code, so it doesn't need a well-defined ABI to interact with other C++ code. You can build it to match however you're building the rest of your code.

#5292932 Confused About Frames Per Second

Posted by Pink Horror on 22 May 2016 - 03:44 PM

I am confused however because it typically ends up being > 1000 fps. If it drops below 400, I start to notice a lag. If it were to run at 60 fps it would be cripplingly slow. But 60 fps is what most games run at, isn't it? That is my understanding anyway. Why are the numbers I'm seeing not matching up with my understanding? Is this method incorrect?

It's your own code. You should be able to describe what is happening better than "lag". You should be able to see in your code what is happening.

I didn't see an answer to this question: (Please excuse me if I missed it.)


1.  I assume your objects all are moving based on the deltaTime?!  If not, you will need to make that change because if not, things will move at different speeds on different computers.

To be clear, where in your code do you determine how far something should move in one frame? Does the time factor into it? You're almost certainly doing it wrong, if frame rate breaks your game in any way other than how it looks.

#5292550 Introducing Stanza: A New Optionally-Typed General Purpose Programming Langua...

Posted by Pink Horror on 19 May 2016 - 06:50 PM

That tab thing gives me an idea. If I ever make a language, you'll be forced to have whitespace around any binary operators. No more "a+b" in my language. The inherent productivity will be huge.

#5291986 Trying to draw area from image fails.

Posted by Pink Horror on 16 May 2016 - 08:58 PM

float topborder    = (1 / n)	  * (t - 1);
float bottomborder = 1 - ((1 / n) * (n - t));

-> Topborder results out of the selected square - 1   times  1/n  

-> Bottomborder is   1 minus  1/n times  the ammount of squares minus the chosen one


Let's think about this really simply.

We'll pretend you have a texture that is 8 units tall (I'm using "units" because I don't want to bring pixels into this). Each image you want to display is 1 unit big. There's no width - we only care about height.

If I want to draw image #1, the top is 0/8, and the bottom is 1/8. The next pair is 1/8 and 2/8. The next is 2/8 and 3/8. The next is 3/8 and 4/8. Do you see a pattern here?

(1/n) * (t - 1) ... looks ok
(t - 1) / n ... that looks a little better

1 - (1/n) * (n - t) ... oh dear, let's see what we can do to check this.
(n/n) - (1/n) * (n - t)
(n/n) - (n - t) / n
(n/n)  + (t - n) / n
(n + t - n) / n
t / n ... that checks out, too.

I guess it's just the integer math stuff mentioned above. You still might want to try to keep the math simple, if possible.

Edit: Note, it's common to save a reciprocal like (1/n) to a variable, and multiply by that instead of dividing by n. However, I don't write the math that way on paper (or type it like that into a forum).

#5291727 Templated Function results in Circular Inclusion

Posted by Pink Horror on 15 May 2016 - 02:03 PM

Why is IApp inheriting from Component? From what we can tell here, a Component is something that has a pointer to IApp. Is that just going to be null for the actual IApp, or will it point to itself? I have a feeling you don't really need to inherit from it.

Circular references aren't always bad, but they are still something you can try to avoid.

If necessary, you can split the definition of the templated function out of the header file defining the class, and put it in its own file. Or, you could put both of these classes in the same header and just do everything in the right order. The two classes depend on each other being included together anyway.

Still, this kind of problem is a sign that maybe your design needs rethinking.

#5291620 Loading outward from a point

Posted by Pink Horror on 14 May 2016 - 03:56 PM

Okay, Ill explain in more detail. I calculate where the player is in chunk position, so I know which chunk they are in. So, what I want to do is:


1. Load that chunk

2. Load the chunks surrounding that chunk

3. Repeat 2 with the new chunks (imagine an expanding circle)


Even more example:


4  4  3  4  4

4  3  2  3  4

3  2  1  2  3

4  3  2  3  4

4  4  3  4  4


(Numbers in order of loading)

The generic way to expand outwards through a graph is Dijkstra's algorithm for a shortest path tree.

You would load the player's chunk, then stick all of its neighbors into a queue that's sorted by distance to the player. Then keep taking new chunks out of the queue, loading them, and putting the neighbors into the queue (while keeping track of which ones were already loaded, so you don't load them again). You can stop when you've loaded enough chunks or when the queue is empty.