Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 28 Feb 2011
Online Last Active Today, 12:46 PM

#5256062 C# Garbage Collection and performance/stalls

Posted by Bacterius on 07 October 2015 - 12:56 PM

Use value types like structs for temporary allocations, these are limited to their scope and are efficiently released when the program's flow exits their scope. Then you don't need to bother the GC with a million tiny 16-byte objects that are created and immediately destroyed every frame.

#5255970 Unpredictable, ubiquitously rng seed

Posted by Bacterius on 07 October 2015 - 03:04 AM

So again, the mechanism I propose is:
* Player chooses a move MOVE and a long (say 128-bit) random number SALT.
* First message is HASH(CONCATENATE(MOVE,SALT)).
* Once you have the message(s) from the other player(s), you submit a second message, which is CONCATENATE(MOVE,SALT).
* Collect the second message(s) from the other player(s), and verify HASH(SECOND_MESSAGE) == FIRST_MESSAGE.
* Compute the XOR of all the salts, and use that as the seed for a PRNG to be used in resolving the turn.


Another benefit of this approach is that the seed will be uniformly random as long as at least one player generates a uniformly random salt, unconditionally. If exactly all players collude, they can force the seed to be the same as last turn's, or anything really, but this scenario is not interesting as if all players collude then they need not perform any commitment scheme to begin with and can just do whatever.


Although I would personally use PRF(SALT, MOVE) with the salt keying the pseudorandom function family (HMAC with a strong hash function is ubiquitous as a PRF and will do nicely) instead of concatenating the salt and the move. Naive concatenation of bitstrings feeding into plain hash functions tends to lead to subtle but devastating vulnerabilities such as length extension attacks, especially if not all of the inputs are fixed-length. If you're not careful you could accidentally (and completely invisibly) destroy the binding properties of your scheme.

#5255870 Unpredictable, ubiquitously rng seed

Posted by Bacterius on 06 October 2015 - 01:01 PM

Isn't it a problem that if I receive the other player's move I can pick my move in response? You can still solve that problem with my two-step approach (I am sure I am not the first person to think of it, but I don't know of a better name).


It's called a commitment scheme.

#5254750 Why did COD: AW move every file into the same folder where .exe is?

Posted by Bacterius on 30 September 2015 - 04:06 AM

Besides, why do you care? It works and that's enough.


I downvoted your post because with that reasoning we'd all still be programming software in 8-bit assembly. There's nothing wrong with asking why some games do some things differently than others, it can spark interesting discussions especially regarding file packing, asset loading etc, even if the actual answer is as simple as "no reason, it just worked well enough that way". Answering "why do you care" is no way to foster a community of thoughtful and well-rounded programmers.

#5254329 Singleton and template Error (C++)

Posted by Bacterius on 27 September 2015 - 11:41 PM

I have to agree with Sean here, I am seriously tired of dealing with the cognitive overhead of dependency injection frameworks that have me forced to pass the same damn object around everywhere because it's sufficiently basic and low-level that everything needs it, and at the end of the day it's still a global because everything everywhere has a reference to the exact same object. Things are just as bad as with a global, except now I have a dependency injection framework with it and my code's simple logic is obscured by a weird meta-language to describe its relationship with other simple dependencies (parameter-passing in constructors/factories, annotations, XML dependency trees; pick your poison). I do not see a problem with having genuine services as long as their interface is sane, nor am I against explicitly codifying abstract dependencies when it makes sense and adds value. I have a brain and my colleagues do as well, and at work I find that most of it is being used working with against "modern" design patterns and contorting straightforward code to fit someone else's idea of "decoupled code" instead of actually implementing business logic, and probably producing far more bugs as a result. As everything else in life, design principles become bad and dangerous when taken in excess. If in doubt, stop and think.


Anyway frob I found it interesting that you used the word "generally" followed by an unconditional statement. What in your opinion would be an uncommon use case where a singleton or service locator would be a sensible design choice?

#5253774 Lua C API tutorial / book

Posted by Bacterius on 24 September 2015 - 01:41 AM

Programming In Lua, 3rd edition. Like a quarter of the book is dedicated to the C API and the rest is not bad either.

#5253106 JavaScript Platformer Level Format

Posted by Bacterius on 19 September 2015 - 05:37 PM

I don't see a problem with using this to grab the next level, one thing you could do if you don't want your game running in the background is display some kind of loading screen while the file is being retrieved, something like:


1. show a loading screen in the middle of the page or something (as a DOM element like a div or whatever)

2. send off XMLHttpRequest with an onready callback that goes parses the json and loads the level, and then hides the loading screen when it's done

3. resume running the game...


I don't think hardcoding the level in your game is a good idea. It's okay to prototype but having it on the server allows for plenty of interesting mechanics like letting users upload and share their levels, etc...

#5252293 Linux c++ debugging

Posted by Bacterius on 14 September 2015 - 11:55 PM

I use Valgrind primarily. I very rarely need to break out an actual debugger, the times I did I just used gdb and it worked fine, though I could see it worthwhile to invest in both better front-ends and actually learning how to use it efficiently.

#5251881 Is there a language like Python but without the tab requirement?

Posted by Bacterius on 12 September 2015 - 08:07 AM

If your most important goal is sensible syntax, you need an Algol-family language. Weird that none of them ever caught on.


I guess Pascal is not really "in" any longer these days, especially on a game development forum, but Ada and Lua are pretty popular (though not for the same reasons). Plus Lua has first-class functions and proper closures which I guess comes more from functional languages like Lisp, although the syntax is very sensible and easy to grasp.

#5251850 Is there a language like Python but without the tab requirement?

Posted by Bacterius on 12 September 2015 - 04:17 AM

It runs faster too, because the CPU doesn't have to keep scrolling down.


Wouldn't it have to scroll right way more though? This is why I limit my line lengths to 80 characters, 120 is acceptable but I can definitely feel the slowdown on longer lines. They just run slower.

#5249823 Strange pinching effect with raytraced reflections

Posted by Bacterius on 30 August 2015 - 11:43 PM

Your code calculates (dir - dir * dot(dir, norm)) * 2, whereas you should be calculating dir - dir * dot(dir, norm) * 2, that is:

Vector3 ReflectionDirection = newRay.direction.nor().cpy().sub(surfNorm.scl(newRay.direction.cpy().dot(surfNorm)).scl(2.0f));

Or just:

Vector3 ReflectionDirection = newRay.direction.nor().cpy().sub(surfNorm.scl(2 * newRay.direction.cpy().dot(surfNorm)));

This is incidentally the main reason why I strongly dislike the lack of (reasonable) operator overloading in languages, it makes it impossible to write such things in a sane way (and, no, separating this simple equation into three or four temporary variables is not sane either). But anyway this is where the pinching comes from.


(actually it's pinching not so much because the reflection is wrong but really because of your error the resulting reflected vector is not unit length, which wreaks havoc on the rest of the ray tracing code something fierce; so a good thing to do whenever stuff looks really weird is to look at your directions vectors and check if they are actually unit length; if they aren't, you've screwed up somewhere)

#5249675 Background color ruins Antialiasing

Posted by Bacterius on 30 August 2015 - 02:56 AM

It could be that it was running your old code before you added anti-aliasing or something, dunno. If it works now then cool, looks nice by the way smile.png

#5249618 C++ | Fixed Byte Size

Posted by Bacterius on 29 August 2015 - 05:23 PM

That code is illegal JohnnyCode. You cannot reinterpret m_Memo (which has no alignment constraint, being a pointer to char) to a pointer to WORD or DWORD, which have alignment constraints (2-byte and 4-byte boundary respectively). Your code will work "correctly" on x86 systems like  your desktop/laptop because the processor takes care of the unaligned access and fixes it up itself; you will obtain some kind of bus error on less generous processors like many ARM ones.


You can see the access cannot be aligned since you reinterpret both m_Memo and m_Memo + 14 as pointers to DWORDs, and clearly these addresses can't both be aligned to a 4-byte boundary. If you want this code to be portable (which, hey, you might not; if you are only interested in supporting x86 hardware then this will work fine, you'll just incur a small performance penalty each time you access these fields due to the CPU having to do extra work for unaligned access) then you can use memcpy to safely unpack the bits of m_Memo into words and dwords.


Oh, and you also don't handle endianness. Not a problem on x86 as all x86 chips are little-endian AFAIK, but could cause strange behaviour depending on where the header is coming from!

#5249539 How would I be able to do this in C++?

Posted by Bacterius on 29 August 2015 - 04:43 AM

Did you remeber to #include ?


He is probably not using C++11.

#5249530 How would I be able to do this in C++?

Posted by Bacterius on 29 August 2015 - 04:15 AM

A Lua "table" is just a generic associative mapping, which maps a set of keys to a set of values. In this special case it also happens to be what is known as a list or array in most programming languages. Read up on datastructures and you should find that C++ also has a notion of arrays, lists, mappings, ...