Advertisement Jump to content
  • Advertisement


  • Content Count

  • Joined

  • Last visited

Everything posted by zalzane

  1. I know you've put a lot of thought into your way of avoiding globals, but your editor example is a good example for passing references. At first many may think, I have this model editor and it can only do one model at a time. I've made a model editor and made the same assumption. Sure if that's true, just use a global or singleton rather than a more complex organization just to avoid using globals. But really, will an editor only store ONE model? Maybe this editor allows you to load a character model, but it can also load attachments like weapons. The editor can manipulate the character and the attachments. It seemed like only one model was needed, but after adding more functionality, now you need more than one. So when you open a dialog or tool in the editor, the dialog or tool will need to be passed a reference of what it will manipulate. I'll admit my example really wasn't that great, but inheritance based global access isn't around to replace something like a class full of references.   An infinitely better example would be an static-inheritance class giving access to something like the graphics device. On one of my older projects, the "sprite" class is typically accessed very far down the call stack. From the entrypoint of the program, you have to go through a few layers of gamestate logic, then UI logic, then all the way at the bottom is the sprite class. The sprite class needs access the graphics device, or whatever class is handling the graphics device. Instead of passing down a reference to the graphics device down a dozen layers of call stack, the Sprite class would inherit from a static class that contains the graphics device.   This way, access to the graphics device has to be explicitly defined through the use of inheritance, and any usage of the graphics device can be found by just looking at all the child classes that inherit from it. In addition, it's one less piece of trash floating around the global namespace.   I'll admit it's hacky as hell, but I'd rather have an ugly hack than restructure 10k lines of UI logic.
  2. One of the clever, but more contraversial alternatives I've found for sharing data between classes is to use inheritance/static fields. Let's say you're programming a 3D editor of some sort, and a list of vertexes in your model has to be shared between many classes. The options in this thread include simply passing the list as a parameter, setting up a singleton, or setting up a container class that gets passed at runtime.   With my inheritance method, you set up an abstract class that contains protected static fields for shared information - such as the list of vertexes that has to be shared. Any class that needs access to those vertexes would inherit the abstract class.   This can be extended into a tree of inheritance to allow different child classes to have different read/write permissions on the abstract class' fields, but I would restrain myself from doing this too much at risk of ending up with 3-4 depth inheritance trees.   The most significant issue with this model is that without the proper visualization tools, maintaining code that runs under this system can be very complicated, especially if you have poor docs.  In addition, if someone else was to read your code without knowing what you're doing - it's likely they would get very confused very fast. If you use this system extensively, I suggest writing an addon/macro for your development environment that lets you inspect what kind of inherited fields each class has without actually opening up the abstract class.
  3. Triangle strips are a major pain in the ass, especially when you're programatically generating geometry. Don't use them.   Depending on how you generate the terrain, it may be faster to just generate it each time the game loads rather than loading it from a file. I have a demo that uses opencl to generate terrain, and it can generate terrain an order of magnitude faster than it would take to load said terrain from disk.   For figuring out which triangle the mouse is mousing over, check this out.   You can basically copypaste their code for it.
  4. You could construct a linked list to represent the planet's mesh.     enum Direction{ Above, Below, Left, Right }; struct Vertex{ float phi; float theta; float r;  float cost; Vertex *neighbors; };   Using this method, the only real effort required is in the initial assembly of the linked list. For pathfinding you would just iterate through the linked list like you would for a normal array.
  5. zalzane

    Your Worst "Gotchas" ever in programming

    pretty much anything i've done involving c++ has been riddled with gotchyas, I hope I never have to use that language again
  6. Here's a short list of features that C# has that java doesn't. To be quite frank, C# was really designed to be a 'better' Java, and has succeded in many aspects. - Value types vs. reference types - Named and optional arguments - Built-in events - Lambda expressions - Value types allowed as generic parameters; generic constraints - Co/contravariance - Delegates - Methods are not overridable by default - Better interop support with unmanaged code - Pointers - Properties (getters/setters) - Operator overloading - 'async' methods - More flexible exception throwing* - Ability to allocate memory not managed by the GC - Standard IO library that is not complicated and overly verbose ================================================================================ * adding 'throws' to a method in Java requires snowballing changes to all methods that make use of that method, which requires changes to those methods, etc... Also, Java being more portable than C# is partially incorrect. Through Mono, you can compile C# code for a huge variety of platforms including Linux, Mac, PS3, and loads more I can't remember. The only problem with C# is that we'll never know if it ends up being a microsoft patent trap.
  7. zalzane

    Progamming for beginners

    C++ is the industry standard for games so a lot of people suggest it, but it's a horrible starting point for a beginner looking to make their own games. I back the python recommendation.
  8. zalzane

    Slowdowns / 'Anti-Hotspot'

    Quadtrees tend to be very computationally expensive, and even worse - tend to do lots of heap allocations in loops. I couldn't tell you without looking at your code, but it may be possible that the problem is the garbage collector. If you wanted to stay using c#, you may be able call the GC class and have it clean up after every node is created. It's unusual that the garbage collector would block you that badly unless you were doing LOTS of heap allocations that keep the variables alive for periods of time where the garbage collector can't figure out if it should treat the variables as a short-lifespan object or a long-lifespan object. I suggest you read this article and become more acquainted with the GC.
  9. Everyone in this thread is a naysayer. The first thing you do to create a game engine is to program several games. Take note what kinds of tools and algorithms you reuse in each game, and build a framework off those algorithms. Needless to say, once you've programmed several games, you won't actually be a beginner anymore.
  10. zalzane

    Some newbies (like me) do love to code in C++

    The only people I've ever met who consider C++ to be an adequate solution for creating videogames are people who have never programmed in a language that wasn't C++. The only reason it's still around is because it's what everybody uses, so if you're hiring C++ programmers for a game, you have a lot more choice than if you're hiring haskell or C# programmers.
  11. zalzane

    Is c++ better?

    You probably heard that from some other thread in the beginner's forum. I would take it with a grain of salt, this isn't necessarily a good place for the kind of business analysis involved in determining whether or not microsoft is going to drop XNA. However, it's extremely unlikely microsoft plans on dropping C# any time soon. They invested far too much money and resources to drop it and go back to C++. Assuming I'm wrong and microsoft drops XNA -and- C#, it would ultimately be irrelevant because of mono and monogame.
  12. zalzane

    Is XNA dying and MS forcing to C++?

    Whether or not microsoft condones C#/XNA is irrelevant in the long run thanks to mono/monogame.
  13. zalzane

    how to unlearn a language

    I had the same problem as you OP. C++ was my first language, however after using it for quite awhile I would still have issues with what I call "macro code", or code that dictates how larger parts of a program interact. For me that encapsulated how classes should interact with each other, inheritance, doing #includes correctly, and a few other tidbits. Unfortunately I have never found a text that really teaches how to create good macro code. Here's how I dealt with it and maybe it will help you out. Eventually what happened is I started programming in another OOP language, C#. For C#, OOP is very much more set in stone, and after programming a medium sized project with it, I learned more about OOP than I had learned in almost a year and a half with C++. However this didn't solve my issues with learning how to prevent #include circles, I eventually said 'screw it' and switched over to C# completely. To this day I've never had to tolerate C++'s god-awful translation unit system since then. [spoiler]I promise I dont work for microsoft[/spoiler]
  14. zalzane

    Which level of programming detail is best?

    Big video game companies suffer the same issues as normal companies. There are HR people who have no idea what they're doing. There's a few who do. I would expect the HR guy at Valve or Dice for example to know their shit a lot better than an HR guy at EA or Activision. I'm not saying that every video game HR rep is an idiot, but based on my experience with HR people who hire for any kind of technical job, many of them don't actually know what they're looking for in a new hire other than making sure they fit the job description. Your results may vary.
  15. zalzane

    Navigation in a big world

    I believe this may be a scenario where it would be a good idea to assist with pathing speeds through caching. I assume you're making some kind of adventure game with towns and roads and such. When the world is generated you might be able to cache the roads and the locations where they lead to and kinda "add them" into your current pathfinding solution. For a case in which something is pathing from one side of the map to another, I imagine this would cut down the path generation time by a few orders of magnitude, in addition to having it so npcs actually use roads.
  16. zalzane

    Which level of programming detail is best?

    It's important to remember that you will likely be showcasing your portfolio to a HR manager, not a project manager. In which case it's probably a lot more impressive to see more "visible" kind of work, rather than to have less "visible" work that's in a lower level, but more job-appropriate language. Of course it would be nice to have at least one low-level project to showcase just in case you get someone who actually wants to see how your low-level stuff works, but I think the majority of your portfolio should be flashy stuff that would impress someone who doesn't really know much about what goes on behind the scenes.
  17. zalzane

    A* speed

    OP, probably one of the most overlooked optimizations for a* is that instead of maintaining seperate open and closed "lists", have a 2d array of chars that represent the state of a node (0=n/a, 1=open, 2=closed, 3=unpassable), with a seperate 2d array of uints for important node-specific statistics such as distance travelled. Another extremely useful optimization is to use binary heaps to sort your open list values. I recall that when I tested the binary heap sort versus the std::list sort, the difference in speed was half an order of magnitude, even when there were very few values in the heap which is one of the binary sorting algorithm's weaknesses.
  18. zalzane

    Games no longer fully using PC hardware?

    I don't think you'll see crysis-level games in terms graphical focus unless someone was trying to develop the next benchmark game. (like bf3 for example) My current project is actually extremely CPU-dependent, and even splitting it into 4 even threads with optimizations up the ass it can run slow on my min spec cpu (Q6600). I don't know if any other devs have similar projects under covers, but it wouldn't surprise me if i wasn't the only person who was developing a game that uses a ridiculous amount of resources.
  19. I've been working on this code for quite awhile now trying to get it to run in a reasonable amount of time. It's supposed to be an A* algo that pathfinds between two points while taking into considering a cost grid that represents how hard it is to cross each tile. A typical grid that would be fed to the algo would be 256x256 tiles in size. During profiling I would test between one end of the grid (0,0) to the other end (255,255) and would get atrocious speeds of up to 60 seconds. There isn't much in the algo that strikes me as any kind of heavy lifting, so I'm virtually clueless as to why it's running so slow. Here's the code, I put all the structure definitions involved and did some hardcore commenting. The indenting may be weird because of how the forum interprets whatever the hell my text editor is using for spaces. struct pair_s{ int x; int y; pair_s(int x_, int y_){ x = x_; y = y_; } }; struct node_s{ vector<pair_s> pathToNode; int x,y; float distToDest; float costTravelled; float cumulativeCost; bool hasNodeBeenParsed; node_s(int x_, int y_, float distToDest_, float costTravelled_, vector<pair_s>* prevPath){ x = x_; y = y_; distToDest = distToDest_; costTravelled = costTravelled_; hasNodeBeenParsed = false; cumulativeCost = costTravelled + distToDest; if(prevPath != NULL){ pathToNode = (*prevPath); pathToNode.push_back(pair_s(x,y));//add the current node to path history } } }; void worldgen_c::getPathBetweenPointsAstr(int initial_x, int initial_y, int dest_x, int dest_y, vector<vector<float> >* costMap, vector<pair_s>* retPath, float costMultiplier){ vector<node_s> closedNodes; vector<node_s> openNodes; int gridWidth = costMap->size(); bool** nodesAcctFor = new bool*[gridWidth];//when it comes to checking if a tile has already been added to the node vectors, for(int i=0; i<gridWidth; i++){//it's more efficent to use a 2d array of booleans rather than iterating through a list of coordinates nodesAcctFor = new bool[gridWidth]; } for(int x=0; x<gridWidth; x++){ for(int y=0; y<gridWidth; y++){ nodesAcctFor[x][y]=false; } } //initial node closedNodes.push_back( node_s(initial_x, initial_y, getDist(initial_x, initial_y, dest_x, dest_y), (*costMap)[initial_x][initial_y]*costMultiplier, NULL) ); while(1){ //first we add spots adjacent to closed nodes to the open nodes for(int node=0; node<closedNodes.size(); node++){ if( !closedNodes[node].hasNodeBeenParsed ){ //check to see if closed node in question has already had its adjacent friends added to open nodes for(int x_off=-1; x_off<=1; x_off++){ //checking cardinals and diagonals for(int y_off=-1; y_off<=1; y_off++){ if(x_off==0 && y_off==0)//we dont care about the node we're sitting on continue; if(closedNodes[node].x+x_off>=gridWidth || closedNodes[node].x+x_off<0 || closedNodes[node].y+y_off<0 || closedNodes[node].y+y_off>=gridWidth)//make sure node within b ounds continue; if(nodesAcctFor[closedNodes[node].x+x_off][closedNodes[node].y+y_off])//making sure node isnt already added to one of the tree things continue; //now add the node to the openNodes vector float pathcost=1; if(x_off != 0 && y_off != 0) //if going diagonally, higher pathcost pathcost=1.4; openNodes.push_back(node_s( closedNodes[node].x+x_off, //x val closedNodes[node].y+y_off, //y val getDist(closedNodes[node].x+x_off, closedNodes[node].y+y_off, dest_x, dest_y),//distance to destination closedNodes[node].costTravelled + (*costMap)[closedNodes[node].x+x_off][closedNodes[node].y+y_off]*costMultiplier + pathcost, //heuristic cost &closedNodes[node].pathToNode//path to old node ) ); nodesAcctFor[closedNodes[node].x+x_off][closedNodes[node].y+y_off] = true; } } closedNodes[node].hasNodeBeenParsed = true; } } //now we check each open node and see which one has the lowest cumulative cost int lowestCostIndex=-1; float lowestCostValue = 4294967296; for(int i=0; i<openNodes.size(); i++){ if( openNodes.cumulativeCost < lowestCostValue ){ lowestCostValue = openNodes.cumulativeCost; lowestCostIndex = i; } } //now convert the open node to a closed node closedNodes.push_back( openNodes[lowestCostIndex] ); openNodes.erase(lowestCostIndex + openNodes.begin() ); if(closedNodes[closedNodes.size()-1].x == dest_x && closedNodes[closedNodes.size()-1].y == dest_y){ //see if we're finally done (*retPath) = closedNodes[closedNodes.size()-1].pathToNode; break; } } for(int i=0; i<gridWidth; i++){//cleanup delete[] nodesAcctFor; } delete[] nodesAcctFor; return; }
  20. zalzane

    A* speed issues (C++)

    [/quote] oh wow, thanks for the incredible feedback. It's not often that I can get feedback at that level of detail/insight, thank you.
  21. zalzane

    A* speed issues (C++)

    thanks guys, the issue was with the comparasion/sort stuff and binary heap thing pretty much fixed it
  22. To move an image slowly, you'll need to teleport it over towards the destination just a tiny bit each frame to make it look like a smooth animation. Depending on the speed and smoothness you want it to "move" at, it might take a few dozen to a few hundred teleports. In order to get what coordinates you should teleport the image to for the next frame, you'll take (FinalPixelX-InitialPixelX)/totalFrames to get the number of pixels the image should move in the X direction per frame. The same formula applies in the Y direction.
  23. zalzane

    How to keep the trolls out of online gaming

    unfortuantely the most powerful solution I have observed is to have your game only appeal to a very specific clique. The best example of this is EVE Online. EVE has a ridiculious learning curve, and the turnover rate is enormous. However as a result it has one of the most supportive, positive communities out of any MMO out there. The kind of people who you might define as trolls usually don't have the patience to play a game like EVE, and it has the pleasant side effect of rooting out many younger players as well. It may be similiar to a nuclear option, but if you absolutely want your game to be free of trolls it may be good to take such a approach.
  24. OP, it might help to use an opengl debugging software like gDEBugger. Have it put a set the program to break on gldrawarrays, and on the breakpoint useit to look inside the VBOs to make sure everything looks okay. Usually when I get an opengl error like the one you describe, it's because the coordinates were uploaded to the VBO wrong or weren't uploaded at all.
  25. zalzane

    LOD Heightfield

    can you use a smaller datatype for each vertice? if your world is only going to be 2k by 2k at max, you may be able to get away using shorts instead of what you're using now.
  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!