• Advertisement


  • Content count

  • Joined

  • Last visited

Community Reputation

400 Neutral

About rogierpennink

  • Rank
  1. class instances and game state

    From what I gather, you suffer from the same problem that I had a few years back (and still have, to some degree). Basically, you worry too much about what's the best, the most optimal, and the most well-designed solution to your problem. In itself that is a commendable goal, but if it means you're not getting anything done for fear that the code you're writing isn't as well-designed as it could be, then it becomes counterproductive. Take for example, collission detection; unless you've made many games you shouldn't expect to get the best implementation going on your first attempt. It's much better to simply get your game working, with collission detection, and THEN look at how you might be able to re-use the collission detection code (by, for example, making a class for it). In general this is how you end up with a small library of re-usable code after a few projects that all shared certain basic principles. From experience, this is a much better learning path than trying to figure out the most optimal solution upfront and then still getting frustrated anyway. Also, if you're not up to speed with object oriented programming yet, I'd focus on learning how to work with classes before you attempt to apply them in a bigger project. Once you've played around with them you'll start noticing that finding object-oriented solutions also comes much more naturally as you approach problems from a different perspective.
  2. question about OOP

    Why does your Networks class need to know about your Game class though? I do not know how exactly you're 'designing' your game, but if my assumption that your Networks class only handles everything network-related is right, then, in theory, it has no need to know of the existence of your Game class. I think it would pay off for you to take a look at your class design, trying to get rid of any dependencies that Networks may have with your Game class.
  3. Indices problem with terrains

    Quote:should be all you need to render 1 quad = 2 tris =(2x2 verts) with a trianglestrip. But I'd have to check to be sure. You highlighted the problem exactly with that first line :P My FlatGrid class uses a triangle-list by default, but I had not done the same thing for my heightmap-terrain. It was therefore being rendered as a trianglestrip with 6 indices per square - which as you say, yields unexpected results. I'll try your code for both the grid and the terrain though, it's always nice to save an extra 8 bytes of indices per square :)
  4. Indices problem with terrains

    I have been working on a simple scenegraph-driven engine for a short while, and recently I encountered a very frustrating problem while adding terrain. Because I want to keep things simple for now, my engine's terrain basically consists of loading RAW image files and using those to get the terrain height data from. Other than that, I figured the terrain is exactly the same as a 'grid'. I already wrote code for making flat grids, so I figured I could re-use most of that code and only change the part where the height of the vertices is set. Strangely enough, the terrain code seems to have a problem with the way indices are calculated - even though this way is near enough exactly the same as the grid code, which does work fine. They say an image is worth more than a thousand words, so here are two images showing the problem: Top-down view: From underneath: The large flat area is the flat grid, which as you can see, works like a charm. Then the smaller 'grid' is the terrain. For testing purposes I left out the height information and the RAW image it reads from is only 3x3 so it is easier to debug. In essence, the code of the grid is exactly the same as the code of the terrain at this point. Because I believe it to be a problem with the indices, here is the code that calculates them: int numIndis = m_width * m_depth * 6 - 3; unsigned int* indices = new unsigned int[numIndis]; int i = 0; int numVertsPerRow = m_width; int numVertsPerCol = m_depth; for ( int z = 0; z < numVertsPerCol - 1; z++ ) { for ( int x = 0; x < numVertsPerRow - 1; x++ ) { indices[i++] = z * numVertsPerRow + x; indices[i++] = (z + 1) * numVertsPerRow + x; indices[i++] = z * numVertsPerRow + x + 1; indices[i++] = z * numVertsPerRow + x + 1; indices[i++] = (z + 1) * numVertsPerRow + x; indices[i++] = (z + 1) * numVertsPerRow + x + 1; } } As far as I can see, there is nothing wrong with it, but the screenshots really do seem to indicate it's an indices problem. Any help would be greatly appreciated! :)
  5. Thus far I've found the gamedev forums, and this forum in particular, to provide very useful information on everything that has to do with game engines. I've read many 'classic' threads where Yann L. explains everything from shadow mapping to scene graph implementations, and they've proven very helpful. However, in the process of working on my own rendering, I'm finding it difficult to ty all these theories and 'best designs' together in a coherent design that makes sense for me. I'll list the issues I'm running into and my thoughts about them one by one below... Also note that I'm using OpenGL, and though the renderer is designed to easily allow support for other libraries such as Direct3D I see no need to this yet, so I may sometimes refer to OpenGL specific things. The scenegraph Everything I've read about the subject has led me to believe that spatial ordering and other optimization techniques don't belong in a scene graph. Currently I have a very limited SceneGraph class that consists of GroupNode and GeometryNode objects only (both are derived from SceneNode). GroupNodes can have children, GeometryNodes can't have children, so all geometry nodes are leaves of the tree. This works exactly the way I thought a scene graph is supposed to work (I can add parent-child relations between objects in a scene, and transformations in each node are relative to the parent node). Though many threads I've read about scene graphs add more types of nodes, I probably won't be doing that in the near future because I want things to remain as simple as possible until I've grown more comfortable with the design. So far so good, but my understanding starts lacking when it comes to passing objects from the scene graph to the Renderer. This has to do with the way in which GeometryNodes are defined in my engine: GeometryNode The only thing that makes a GeometryNode different from its parent, SceneNode, is that it contains a BaseGeometry object. The BaseGeometry class is the parent class for all geometry in the engine. So you can make a BoxGeometry object, for example, that inherits from BaseGeometry and which defines the geometry for a box. I'm also working on classes like 'CaligariGeometry', or '3DSMaxGeometry' that will load geometry from disk. Similarly, I imagine there would be TerrainGeometry objects. Because all these Geometry classes inherit from BaseGeometry, they can all be passed to GeometryNodes in the scene graph. The scene graph doesn't really care what the geometry represents, it only knows about GeometryNodes, but what they contain is not of the scene graph's concern. BaseGeometry BaseGeometry, as said, contains geometry data. I currently distinguish between many types of buffers. Think IndexBuffer, VertexBuffer, NormalBuffer, TexcoordBuffer etc. The reason why I did this is because I'm using the OpenGL buffer objects extension, and the framerate was higher when I used this system of many buffers for one object, rather than one large buffer with Vertex objects that contain everything from vertex position data to texture coordinates. I'm quite sure my tests are to be taken too seriously as I've never used any substantial number of vertices. Thus far all I'm rendering is a 100x100 grid with a couple of boxes on it, because I cannot load arbitrary 3D file formats yet that would allow me to more easily load more data. This is actually my first problem. With so many buffer objects for each (potentially small) geometric entity I foresee the rendering being horribly inefficient. Suppose you render 10,000 boxes with this scheme. Every box has 8 vertices, 8 colours, and 36 indices. That means this scene requires the use of 30,000 buffer objects whose contents all range from 8 to 36 indices. I thought it would be more efficient if the Renderer class kept several large buffers itself, but as far as I know that means you'd have to copy the geometry data into the renderer's buffers every frame (because with culling etc. going on I can't be certain if a geometric entity is still supposed to be in the renderer's buffers or not), which defeats the point of using vertex buffer objects altogether. The second thing I have a hard time understanding how culling comes into play. It seems that using a scene graph for culling is not good; a scene graph is not meant for that. Reading through one of the threads on gamedev.net where Yann L. explains all about terrain and scene graphs, I got the impression that it may be good practise to let geometry cull itself. I can see the advantages of this in for example, a TerrainGeometry class, where the TerrainGeometry would implement a spatial partitioning scheme. This way the scene graph will still think of the terrain as a single "GeometryNode" entity, but the terrain itself could be a quadtree without the scene graph ever knowing. For terrain it'd work well, but other entities? Would it work to have an OctreeGeometry as a base class and have, for example, classes like 3DSMaxGeometry also inherit from OctreeGeometry (next to BaseGeometry)? I'm guessing this won't work as well... Animated models aren't really 'optimised' by octrees (from what I've read), and I can't see the benefit of putting small static geometry in an octree either. An other solution could be to work with several 'phases', first of which would be to update the scene graph, and then send all geometry to a culling phase. The drawback I can see to this is that all geometry will be treated equally, which I assume to not be desirable in all cases. Culling algorithms are going to be different for different types of geometry, so some distinction should still be made. These are just some of the questions I'm facing, and perhaps I shouldn't even bother with them and proceed making a horrible inefficient renderer that is to be improved upon later, but I'd still like to hear some opinions, as I find it nearly impossible to 'move on' without addressing any of these concerns. I constantly fear that I'm making my engine so inefficient that the second I'm done with it, I'll want to scratch half of it. Eventually, facing these questions will be inevitable so I thought I might as well do it now. Thanks in advance for any feedback :)
  6. texture mapping issues/questions

    The code wouldn't have imported any files at all. fopen gives you a file pointer and that's it. In order to read information from the file you'd have to look at using fread. Or alternatively, if you're using C++, you might take a look at using streams. In any case, getting the data from the to-be-loaded file is the easy part. Interpreting it isn't. However, I think MJP is right when he says that you may want to look at using some sort of image loading library. Writing importers is tedious, especially if you're still working on getting the hang of basic concepts like file I/O in general.
  7. texture mapping issues/questions

    The differences between various image formats generally all boil down to... well, exactly that: their format. A .bmp image for example, being the easiest to load, basically stores the raw image data with just a little header information (although compression is also an option). More 'advanced' image formats may use compression methods to cut down on the file size, and consequently, these formats store information about which uncompression scheme to use along with other data, such as the number of bits per color etcetera. So yes, as to your second question, different filetypes need different importers. If you're interested in writing importers yourself, you might find it easy to start with 24-bit bitmaps (.bmp). The format is easy enough to grasp. This page features a tutorial: http://www.runicsoft.com/bmp.php. If you don't wish to write importers yourself, you could look at a popular image importer library like: http://openil.sourceforge.net/ As to your last answer, I have no experience in the commercial games industry, so I can't comment. But I would suggest taking a look at your favourite games in Windows Explorer and see what image types they use. Often the data'll be compressed, but I'm sure that a bit of googling can help you find uncompression programs... Edit: Your code suggests you may still be working on grasping some basics in C or C++ (your code is C), but there is one thing that stood out:file_current=fopen(filename,"r"); if ((file_current=fopen(filename,"r")) == NULL)Is there a reason you try to open the file twice? I suggest leaving the first line intact and changing the second line to:if ( !file_current ) // Or: if ( file_current == NULL ) Regards,
  8. Best way to store input?

    I am personally a fan of the observer pattern, but that may also partly be because I've spent a lot of time programming with Java (and Swing). Since the observer pattern is mainly used in event-driven designs, I'd be inclined to say that using it also comes in handy with multiplayer game programming which tends to be event-driven as well. I think that in general it is safe to say that there is no 'best way'. Choose the method that suits your program's purpose best.
  9. The problem is, both humanPlayer and computerPlayer are 'instance variables'. That means they can only be accessed when there is an object of the class they're in. Static members, on the other hand (also called class variables), can be called even if there is not an instance of the class available. So it logically follows that you can't use non-static variables in a static method. To fix it, either make the method you're calling from non-static, or make the members static...
  10. Instead of toString, wouldn't it be simpler to just cast the Object to a JButton and use getName()? If you intend to have different objects be passed into the shotFired method, you can always use the instanceof keyword to determine what cast to execute. private void shotFired( Object buttonClicked ) { if ( buttonClicked instanceof JButton ) { JButton button = (JButton)buttonClicked; System.out.println( button.getName() ); } }
  11. Hey everyone, I am making a java IRC client and I use a JTextPane with a HTMLEditorKit for the output in channels. Recently, I've refactored my code to use a new class, a ChatWriter to print the formatted text into whatever channel, given a styledDocument and an EditorKit. The most important reason for making this change was to have all the formatting placed in a single class, rather than having it spread out over all the messagehandling code as I used to do before. However, a nice side-effect I figured there to be, was that I could eventually use the ChatWriter to add logging features etc. as well. For this I needed to change the way I replaced smiley-text with icons (emoticons). Before ChatWriter, I simply called the setIcon method of the JTextPane class after having set the selection over the smiley-text that ought to be replaced. With logging on the to-do list, this is no longer viable, as I would like to log any smileys that were used as well. Therefore, I switched to using setCharacterAttributes, which supposedly doesn't remove the actual text used for a smiley. The relevant code now looks like this: public void write( final int mType ) { setMessageType( mType ); if ( doPrintTimestamps ) message = printTimeStamp() + message; String output = "" + message; /** Printing of text ought to happen on the event dispatch thread. **/ SwingUtilities.invokeLater( new EDTAction<String>( output ) { public void run() { if ( doc == null || kit == null ) return; int start = doc.getLength(); try { kit.read( new StringReader( obj ), doc, doc.getLength() ); /** Parse smileys. **/ Iterator it = V5WebChat.instance.getResourceManager().emoticons.keySet().iterator(); while ( it.hasNext() ) { int i = start; String line = doc.getText( i, doc.getLength() - i ); String emotxt = (String)it.next(); ImageIcon emoticon = V5WebChat.instance.getResourceManager().emoticons.get( emotxt ); while ( line.toLowerCase().indexOf( emotxt, i - start ) >= 0 ) { int offset = line.toLowerCase().indexOf( emotxt, i - start ); /** Create a new attributeset with the current emoticon as icon. **/ MutableAttributeSet attributes = new SimpleAttributeSet(); StyleConstants.setIcon( attributes, emoticon ); doc.setCharacterAttributes( i + offset, emotxt.length(), attributes, false ); i += offset + emotxt.length() - 1; } } } catch ( IOException e ) { System.out.println( "IOException@ChatWriter.write" ); } catch ( BadLocationException e ) { System.out.println( "BadLocationException@ChatWriter.write" ); } } } ); /** Clear/reset everything. **/ message = actor = channel = ""; victims.clear(); params.clear(); isAction = false; } Unfortunately this does not produce the expected results. Instead of neatly making all textual smileys appear as icons, it only changes the first occurrence of a textual smiley into an icon, and leaves the rest unchanged. This results in the situation that as long as you just use no more than one of each emoticon, it'll look as expected, but as soon as you want to print, say, two ':p' smileys, it only shows the first occurrence of ':p' as an icon, and the second occurrence is left untouched. Of course, I have spent a long time searching for similar issues on google, but the only result I got was this post: http://coding.derkeiler.com/Archive/Java/comp.lang.java.gui/2005-04/msg00362.html and a reply to it: http://coding.derkeiler.com/Archive/Java/comp.lang.java.gui/2005-04/msg00366.html The reply is what looks most interesting to me. It mentions that it could possibly be a bug in the java source; which makes me wonder - is there a work-around? I am not entirely sure what the person from the reply means by saying "use unique Icons (e.g. a Icon wrapper around the original one)". I have tried constructing a new ImageIcon (with the Image of the original icon) for each emoticon, but this too does not solve anything. Any help would be greatly appreciated! Edit: I always find a visual explanation helpful. Shown below is the incorrect output: [Edited by - rogierpennink on April 18, 2008 6:09:27 PM]
  12. OpenGL Texture problem: green appears as pink

    Hmm, I changed that line into:pixels[y * width + pIndex] = ( 0xFF << 24 ) | ( curpixel[2] << 16 ) | ( curpixel[1] << 8 ) | curpixel[0];Then the green showed up, but the red dots were blue... Conclusion? The .bmp file I loaded did store its values in RGB (instead of BGR)... Yet somehow the values my loader read still lead me to believe it was BGR earlier. Anyway, thanks a lot, it worked!
  13. Hey all, I'm busy adding textures to my opengl framework, but a strange change of color keeps haunting my test application. Below is the image I'm using as texture, and as you can see, it's mostly green: However, it appears like so (click on the image to enlarge): This is with lighting turned on (however, without lights in the scene) and a material that is full white (ambient, diffuse, specular, emissive - all are white). With lighting turned off, the texture becomes blue and black. I have triple-checked my bmp loader, but upon loading all color values are still fine. I store the colors in unsigned integers in RGBA format like so:pixels[y * width + pIndex] = ( curpixel[2] << 24 ) | ( curpixel[1] << 16 ) | ( curpixel[0] << 8 ) | 0x000000FF;I have confirmed that the curpixel array (unsigned char[3]) contains the colors in BGR format. Note, this happens in the BMPImage class, and I send the data to opengl with a call to gluBuild2DMipmaps, like so:gluBuild2DMipmaps( GL_TEXTURE_2D, GL_RGBA8, img->getWidth(), img->getHeight(), GL_RGBA, GL_UNSIGNED_BYTE, img->getPixels() );Where img is declared as an object of class Image, but the instance is of BMPImage which is derived of Image. Since I have absolutely no idea what could possibly cause this erratic behaviour I'll refrain from posting more code (unless someone asks, of course) because I am not in the position of deciding what code is relevant, and what code is not. Thanks, Rogier
  14. Function pointers to class methods

    Quote:Original post by CmpDev The page then goes on to describe "functioniods" (also know as functors, function objects etc). If you want to implement your own then the information is on that page else you could always use Boost's Sorry for sounding shirty but you post just sounds like "someone do it for me" If I were the kind of person that wanted people to do stuff for me, I wouldn't have started this project in the first place; as it has taken me quite a few sleepless nights to get where I am now. However, i can see why you would think that way as there are a lot of such posts around... So no hard feelings. Quote:Original post by DeafManNoEars I'll have my camera objects already instantiated so all I need to do is add static functions to my class to wrap the non-static member functions and pass the camera object to my addeventHandler function. Thanks for your input! Unfortunately I find a static function to look still very much like a top-level function, so I'll go and play with functors a bit first :) Regards, Rogier Edit: Thanks for the links to the articles, jcullet. I have not yet worked with boost before; so I'll just take this problem as an opportunity to familiarize myself with it.
  • Advertisement