Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 13 Jun 2001
Offline Last Active Yesterday, 02:12 PM

#5260221 The Big List of Good Design Practices

Posted by Madhed on 02 November 2015 - 05:44 PM

Document every issue, as minor as it may seem. Lots of bugs can be forgotten because "I don't have time for that now, will look at it later"

#5259979 Armour penetration and firearms

Posted by Madhed on 01 November 2015 - 07:22 AM

You could subtract a fixed amount from the DPS when armored and limit the damage to be between 0 and 100.


Base DPS:


Pistol: 100 DMG

Rifle: 150 DMG

Sniper: 200 DMG


Without armor:


Pistol: 100 DMG

Rifle: 100 DMG

Sniper: 100DMG


With armor that subtracts 100DMG:


Pistol: 0 DMG

Rifle: 50 DMG

Sniper: 100 DMG

#5257813 combating udp flood attacks

Posted by Madhed on 18 October 2015 - 02:56 PM

Thanks guys, really great responses.

What about a single person that tries to disturb your service from a typical home line? Would such an event even register if you have enough bandwidth and your server isn't written in a completely dumb way, like forwarding malicious packets deep inside your game before they are discarded?

#5257807 combating udp flood attacks

Posted by Madhed on 18 October 2015 - 02:12 PM

Interesting, I have heard of iptables in a typical web setup before but somehow didn't make the connetion to it being used on a game server. Need to jot down.

But basically this means it's only worthwhile to prepare for these kinds of attacks if you have a large production running and can afford the costs.

#5257796 combating udp flood attacks

Posted by Madhed on 18 October 2015 - 12:11 PM

This is a theoretical question that I have wondered about, so I have no actual code to show here.


Say I have a game server that is accepting client packets at a publicly known port. What is a common method to handle a client trying to DOS the server by flooding it with udp packets?


1. There is a portable way to block communication with a specific IP at the operating system level. I don't know if this atually exists, but it would probably be the most effective solution.


2. Close the known socket and reopen it on another port. While this prevents the rogue packets from reaching the appliation, the operating system still has to handle the packets before it can decide to drop them.

I guess this is cheaper than to drop them at the application level, but it still puts some strain on the system.

Also, the server still has to announce the new port eventually and the attack could continue there.


Did someone here deal with this before?

#5257134 Class / array question

Posted by Madhed on 13 October 2015 - 05:34 PM

You can iterate a std::vector like a normal array using the subscript operator (square brackets)

mObject->vertices[0] // returns the first vertex

Vector is a weird name for that container, especially if you are coming from a math/graphics background.

std::vector is just a dynamic array that you can resize and it manages the memory for you.

You can call vertices.size() to get the number of vertices, vertices.push_back(vertex) to append a new vertex and more cool stuff.


I'd suggest you go through a beginner's tutorial for the stl container classes as they are a fundamental building block of modern c++.

#5257127 Class / array question

Posted by Madhed on 13 October 2015 - 05:06 PM



You are trying to initialize a vector of VertexPos with a list of XMFLOAT3's which is not going to work.


So either you need to make it std::vector<XMFLOAT3> or put another pair of parentheses around the initializer elements like so:

mObject->vertices =
	{XMFLOAT3(0,0,0)}, {XMFLOAT3(0,0,0)}, {XMFLOAT3(0,0,0)}

#5257121 Class / array question

Posted by Madhed on 13 October 2015 - 04:50 PM

Weird, I just tried with VS.net 2015 community edition and it works. Can you post the code of the VertexPos class and the way you initialize the list?

#5257115 Class / array question

Posted by Madhed on 13 October 2015 - 04:20 PM

you can use a std::vector.


If your compiler supports c++11 you can even use the array initializer syntax like in your example.

#include <vector>

class Object

	std::vector<VertexPos> vertices;

mObject->vertices = { ... }

#5256878 Variable size strucs

Posted by Madhed on 12 October 2015 - 10:33 AM

Yes indeed. But then, how do you define the "material" object ? This material object will need to have thoses fields anyway with the arrays


Well, the main idea is that not every draw item will have a unique combination of shaders and textures, etc. By moving the shared data into a material you will save memory in your main draw queue, it's basically the flyweight pattern.


Also you will want to sort your render queue by some criteria which will probably include a material id. Since the number of materials will hopefully be much less than the actual number of draw calls you could use some "heavier" data structures like vectors for the varying length parameters like textures and constants.

#5254146 MySQL statement error

Posted by Madhed on 26 September 2015 - 09:37 AM

No. NULL is very different from 0. NULL basically means the value of this field is not known, whereas 0 is a known numerical value.

#5254124 Intersect ray with heightmap

Posted by Madhed on 26 September 2015 - 06:36 AM

You can  use the Bresenham algorithm to check which cells to test.



#5251613 Sort unit vectors clockwise

Posted by Madhed on 10 September 2015 - 03:44 PM

1. Store them in 4 buckets for each quadrant by comparing the x and y sign.

2. calculate each tangent y/x

3. sort by tangent using your favorite sorting algorithm

4. combine quadrant buckets in clockwise order

#5247837 Structure of object-to-object interaction? (And other questions!)

Posted by Madhed on 20 August 2015 - 05:24 AM

I think these types of mutual interations are better handled through a mediator.

Creature::attack() {
    world.attack(this, enemy, AttackType::MELEE_ATTACK);

World::attack(Creature attacker, Creature enemy, AttackType type) {
    attackHandler = attackHandlers.get(attacker, enemy, type);
    if (attackHandler) {
    else {
        // No AttackHandler found for interation between attacker and enemy

MeleeAttackHandler::doAttack() {
    if (attacker.att > enemy.def) {
        enemy.applyDamage(max(0, attack.damage - enemy.shield));

    if (badluck() > 0.1 && enemy.def > 8) {
        attacker.applyDamage(10); // hurt your hand while punching enemy


This prevents your creatures from directly altering the state of the other creatures and allows you to add specialized attack handlers later on if you want to expand.
A similar system could also be used for other interactions between two or more entities, for example reacting to sounds made by a creature.

#5242743 Breaking out of a nested loop

Posted by Madhed on 26 July 2015 - 06:22 AM

Look ma! no breaks!

int i, j;

for(i = 0; i < 2; i++) {
    for(j = 0; j < 10; j++) {
        // if(i - 1 == j + 1) <- will be true for i==2 and j==0

seriously though, how often will you have a situation where you need a nested loop and break out on an arbitrary condition and continue work after the loop?


Smells to me like a violation of SRP.


Some possible solutions depending on the actual algorithm:


Factor out the loop into another function and just return instead of breaking

or calculate the terminating condition beforehand and adjust the loop boundaries

or collect the affected elements and iterate over all of them