# Hannibal2400

Member

14

189 Neutral

• Rank
Member

• Interests
Programming
1. ## Assigning slots in formations

Unfortunately that doesn't work because it often makes units from back of the formation come to the front which results in a lot of collisions. Though I do use that method selectively.   My code works quite well now. What I do is calculate the distance for every possible assignement with orthogonal movement to the regiment direction being weighted more heavily. After that I check for units that are at about the same distance to the destination for crossings paths and also for units that are further apart for the before mentioned problem of units moving to the front. The result is often very good. But it's very patchworky and still not optimal.     Thanks. I'll take look at that and try to implement it when I have the time. I'll post my results.
2. ## Assigning slots in formations

I actually have a slightly optimised version now. I added additional costs for moving orthogonally to the overall direction of the regiment and it seems to help but it's nowhere near what I'd like it to be.
3. ## Assigning slots in formations

Hey guys,   I'm working on a game where you can control regiments consisting of several units similar to the Total War series. My problem is that I'm not satisfied with how these regiments reform when giving an order that requires rotation of the current formation. The way it is now is not game breaking but really not optimal. What I basically do is allow the unit that is furthest from the destination to pick its preferred spot. That would result in low cost solutions if it weren't for collision. It also just doesn't look right. Here is an image to illustrate an instance that I feel needs improvement.     As you see the unit in the front crosses the path of nearby units which causes collisions and delays. What I need is for units to not cross other's paths if it would cause complications. The problem is that similiar constellation need different solutions depending on unit positions. In this image we have two similiar constellations that need different solutions because otherwise there would be collisions. In the first case you wouldn't want them to cross their paths because you might risk collision although that means a longer distance for the unit that is already behind. In the second case however you would want them cross their paths. There is no risk of collision as they are too far apart and you shorten the distance for the unit that is behind. They even have to cross paths because otherwise the unit that is behind would collide with the one in the front when trying to move past it on its way to its destination.   So what is the best way to guarantee a smooth flow of units without unnecessary path crossings? It works perfectly in the Total War games. I'd really like to know how to do it.   I'm pretty sure there are established solutions to this in the industry. I'm just too uneducated in programming to know them.

5. ## AppGameContainer problem

getState() doesn't initialize state. addState() does. Here is an example from the Slick2D Wiki: http://slick.ninjacave.com/wiki/index.php?title=Game_States. Apart from that I don't see anything wrong. Are you sure you set up your project correctly? Seems like that might be the problem. Something with the LWJGL library. Did you add it?
6. ## AppGameContainer problem

Shouldn't your first two functions look like this?     Why do you call getState() in initStatesList()?
7. ## Help with Jumping mechanic?

I don't see isOnGround ever being set to false in your code. So that piece of code has no effect (unless it's a local variable that you starts with false every cycle). Also you shouldn't just set the velocity to a value but accelerate like you did here Velocity.y += gravity.y * dt.asSeconds(); I think you need to get straight what roles isOnGround and Jumping are playing. As mentioned you don't need both. Also did you check my other points?   I would actually suggest overthinking and rewriting the whole thing as it has too many flaws. I would do something like this bool isOnGround = false; for every obstacle { if player colliding with obstacle { correct position to that of colliding obstacle set velocity.y to zero set isOnGround to true break out of loop } set isGround to false } if !isOnGround { apply gravity } if isOnGround and player jumps { velocity -= jumpingSpeed } apply velocity to position Didn't think it completely through but something around that should work fine. Though this only handles collision from above. If you need collision with other things than the ground then you also need to check collision from below and from the sides. Actually even just for the ground you need to check collision from the side if you have ground blocks with different elevations.
8. ## Is it too early to do some complicated game design

You shouldn't worry too much about design if Pong is your only experience yet. You don't learn programming from just reading books. I would suggest you just start coding a few more simple games and slowly increase the difficulty.   I just googled "easy game programming projects" and found this site with a bunch of nice suggestions. It also links to this site which has lot of neat games which I find even better for a beginner. Just pick one you like and go ahead.
9. ## Help with Jumping mechanic?

for(int i = 0; i < WorldCollisions.size(); i++)             Collision = WorldCollisions[i].intersects(PlayerPos); First as mentioned above you should leave this loop as soon as Collision is true. Additionally you need a reference to the block you collide with as you will need it later. if(Collision) {     player.setPosition(player.getPosition().x, player.getPosition().y);     Velocity.y = 0.0f;     isOnGround = true;     Jumping = false; } Correct me if I'm wrong but after this block the player still collides with the ground as you don't change his position. Meaning every update cycle after that Collision is true and resets the position overwriting any jumping movement. Instead you should correct player's position.y to the ground's position.y + 1.   Also what is this supposed to do? if(!isOnGround) Velocity.y = 60.0f;
10. ## Masses of animated units kill performance

Thank you very much guys for your answers so far.     It doesn't make a difference wether I load the mesh every time or I use a copy because the engine automatically uses the same instance if it sees I'm loading from the same path. I did try using the same animated mesh scene node for every unit by moving it to every position and rendering it. It helps with the performance a bit but not enough.     I'm not quite sure I understand you. Do you mean I should synchronize the animations? I tried something similiar. I noticed that the engine also animated the joint nodes between animation frames. So even though there might only be 10 animation frames the frame number is a float and can take any value resulting in an almost infinite amount of different animation states. I now manually set the frame number so it can only change by steps of 0.5 which limits the animations a lot and gave me quite a boost in performance. And the steps are small enough to not be noticed as unsmooth. However I'm still not satisfied.     Actually I do plan to "cheat" but first I want to optimize it as far as I can without it. I might also use 2D sprites for units that are far away which will help a lot. The reason why I don't only want to do LOD is because there will be occasions with very crowded areas where LOD won't help. I will probably have to use some shader programming which I will first have to learn. DX12 will probably be too complicated for an amateur like me, at least in the near future, and it will also not be supported by a lot of computers so older API will remain necessary.     If by imposters you mean rendering textures instead of meshes for objects far away then I do plan on doing that aditionally to the other optimization.     That actually looks great and runs pretty well on my computer. I'll look into it. As it seemsI will have to do some raw DirectX if I want to get the results I desire. I actually did try to start with DirectX but Microsoft changed some stuff in the SDK and I can't really get the instructions in books and tutorials to work because they use libraries that don't exist anymore. (Edit: I found an older version of the SDK so I'll start learning DirectX. Though I don't know if it's wise to use an old SDK.)   If I can't get the results I want I will have to lower the scale of the game and get along with less units. However I'm not giving up till I tried everything within my capabilities.
11. ## Masses of animated units kill performance

Hey guys,   I'm stuck with a problem that I can't solve on my own. I'm writing a game with a ton of units (aiming at several thousands) and I'm making progress. However I now encountered a problem caused by the mass of units. As soon as animations desynchronize the performance breaks down from 100 to 30 fps. The way I understand it it's due to the high amount of draw calls.   I tried to find a solution and read that usually this is solved through geometry instancing. However I'm not very experienced in graphics programming and the Irrlicht engine which I use doesn't seem to have an out of the box solution. Does anyone know if and how it would be possible with this engine? And if it's not possible is there any other engine that can do it or do I have to go down to programming with DirectX?
12. ## All Jokes aside, what is 6/2(1+2)?

Interesting. I voted 9 but my calculator says 1 for 6/2(1+2) without the multiplication sign. It's 9 for 6/2*(1+2). Didn't even know it made a difference.
13. ## Group reformation

Thank you very much for your answer.   I think I'll try the first and the second approach first. Splitting into subgroups should probably be enough as anything under 100 units gets calculated very fast. If I use the first approach on each subgroup it would even be more accurate than using it on the whole group.   I don't think the fourth approach would work very well in my game but the first three should suffice anyway. Thanks for your help. I'll report back as soon as I get it done.
14. ## Group reformation

Hey guys,   I'm working on an RTS and trying to find a fast way to let a group of up to 256 units change formation. Units new positions should be assigned in a smart way to avoid units bumping into eachother and large discrepancies between the marching distances of every single unit. To illustrate this I made a small graphic with 3 different cases.   [attachment=26858:g4819.png]   The top row shows the desired formations while the bottom row shows the current ones. In the first case the units simply take the new positions in the order they are stored in their container. This is of course the fastest way but also very impracticle as units in large numbers get into eachothers way and occupy near positions that other units with higher marching distances should be taking.   The second and third case show the desired results.   I found a way to solve this problem. However I'm worried that it is too slow. I can't think of a better way, though. This is basically what I'm doing: 1. calculate new positions depending on group destination and formation 2. calculate the distance between every unit and every position 3. save the positions in descending order of the distance for every unit 4. grant the unit with the highest minimum distance the choice of its preferred position 5. remove the now occupied position from the choice pool of the remaining units and repeat 4. until all units are assigned a new position It's step 2 and especially step 5 that take the most time. The time increases exponentially with the unit number. For 128 units it takes 0ms in release mode and 200ms in debug mode of VS C++. With 256 units it already takes about 30ms in release mode and over 1 whole second in debug mode.   Now the results aren't that bad in release mode but of course this is only for one group and in the game there might be several groups that need reassignment at once. I can go with this solution but of course would like a better one. Do you have any ideas?