Jump to content
  • Advertisement

horrificmonster

Member
  • Content Count

    16
  • Joined

  • Last visited

Community Reputation

154 Neutral

About horrificmonster

  • Rank
    Member
  1. horrificmonster

    XML Parser for Asset Manager

      Ah, so I should avoid XML.  I played around with serializing classes, but I was thinking it would be easier to tweak XML files during development. I'll look into 'protobuf' to see if that will meet my needs.         I have a question about this. If I'm writing my data structure to be as general as possible, is there a way for me to use class members in the way you mentioned? The XML Parser class doesn't know anything about what it's parsing, so it won't know what the elements, values, or attributes will be called. I couldn't say element.width, because the element may not even have a width member. I suppose my Level class could be privvy to where in each array the particular attributes are. So I'm assuming what you're saying is use it something like element.attribute[0]? I think I may drop the hashmap in favor of a resizable array, then the calling class will just have to know where in the array to find the data it needs instead of using a string to hash to an array location. I could even use enumeration so it's more like: element.attribute[WIDTH]. There may be a problem with this though, because if I use the array offset as a way to know what's what, then everything has to be in the right order. Every time. That may be more trouble that it's worth.   Thanks for the feedback it definitely got me thinking!
  2. Hello, I'm working on setting up my XML data to keep track of and load levels for my game. I'm using XML so I don't have to recompile/write code every time I want to add a level or change something about a level. I'm pursuing 'data driven' programming here. This is all well and good, except I have a phobia of messing something up before I even try. I've got some pseudocode here of what I'm going to attempt and it seems horribly inefficient. Maybe someone can quell my fears.   First up, I have an XML Parser that will take the level XML data, and return a list of elements. The root element being the levels themselves. Each level element in the xml file will have a level number, and children assets that will themselves contain information for how they should be rendered and the behavior they will exhibit during the game. So far so good (I think!).   Now we get to where the data meets the code. Here is a little pseudocode for my XML Parser (Keep in mind I'll be writing this in Java for Android).   XMLParser Public Accept the xml file from the user and return a list of elements.   Private Initialize and pass the input file to the XMLPullParser library. Reach each tag, and do one of the following:      Create a new element object if it's a new tag      Add the attribute to the element object using a key/value pair, ie: addAttribute("width", "300") I'll be using a hashmap for this. Do this for each attribute found.      Add the value within the XML tags to the element via setValue("tagvaluegoeshere")      For each element found within the root element, add the child to the current element. Recursively process each child element.     Element Public Interface for adding and removing attributes via key/value pair Interface for setting value member Interface for adding children elements   Private Contain 'value', string value that is found between the beginning and ending xml tags. Contain a list of children elements. Contain a HashMap of key/value pairs for attributes found within tags.     Two things: 1. Does this seem like a sound way to handle xml files and putting them into a data structure? I want it to be general so I can use it througout my code. Then I'll set up a level class that will take the level element for the current level and pass it to the assetmanager to load the assets.   2. I'm also worried about resources. Are all of these hashmaps in each element going to use up a lot of memory? I'm not sure how Hashmaps are implemented in Java, but I'm thinking there is probably an array under the hood that is allocating enough memory for the hash function to address the maximum value that it can come up with. If I use the hashmaps to keep track of assets I've loaded in the assetmanager, is it going to slow things down? What is big O for a hash function in Java?     Any help/advice would be much appreciated, thank you!
  3. horrificmonster

    Asset Manager

    Ah that sounds interesting. I could use both of these methods together. Well, except how would the map loading routine know how to reference the hashed assets? All it has is the ID that is set up in the data before runtime... How do I get the performance boost of a hash map with the flexibility of data driven asset management?
  4. horrificmonster

    Asset Manager

    This is great! I'm going to give this a shot, thanks! I was definitely missing the 'map' piece. I would have an xml file outlining all of the assets, then I would think about how I could load all the assets based on this xml file. Then I would think, well heck I'm still going to have to hardcode the asset names when I need to use them in the code. But the way you mention it I can just use a map file to mention these assets by name. Then load these config files and write my code so that it knows nothing about the specifics of the maps/assets.   Thank you!
  5. horrificmonster

    Asset Manager

    Hi All, I'm working on a game, and I've been agonizing how I'm going to implement my asset manager. I really want to do this the 'data driven' way. I have a folder filled with assets. Sprite animations, static assets, etc... These images are composited into one larger bitmap using a bin packing algorithm. This is my image atlas that I use to render to the screen. Now I've been loading and using my assets by hard coding all of the asset loading into the code. For example:     String[] assetsRequired = {"grass1.png","grass2.png","grass3.png","cloud1.png","cloud2.png","cloud3.png","mountain1.png","mountain2.png", "mountain3.png","0.png","1.png","2.png","3.png","4.png","5.png","6.png","7.png","8.png","9.png"};   And this is just getting the background set up.   I pass this array to the AssetManager to take care of the bin packing and setting up texture regions into a member of the AssetManager. Then I reference the texture region something like AssetManager.grass1 in my code.   So now I have all of these references to files and data members littered throughout my code which is a problem. I'm hoping that 'data driven' asset management can help me here but I can't seem to get a grip on how it should work. Either way I slice it, I can't see a way to get this done without hardcoding things like, "grass1.png" in my code.   Does anyone have any ideas on how I should be implementing this?    
  6. horrificmonster

    Problem with Texture Generation

    Ugh, nevermind. Size is reported in bytes, and I'm an idiot! 4 bytes in an ARGB8888, 16384/4 = 4096 limit in either direction. Bonus question, if I had used a 16 bit RGB565 could my texture size be larger? I'm thinking probably not though because it gets upscaled to ARGB8888 when the bitmap is converted into a texture? Or am I wrong there?
  7. Hi All, I'm having a problem with my texture generation on an Android game I'm cooking up. I have all of my textures put together on the fly based on what is needed in the program. I have a bin packing algorithm that loads all of the bitmaps into one larger bitmap that is then loaded into a texture. This works great so far. I use a 2048 x 2048 bitmap to load them into, and the texture works fine there. Problem is, I want to dynamically size my bitmap based on what the device says is the maximum. I have a Samsung Galaxy Note 4 for my device I'm testing on, when I run the following code: int[] maxTextureSize = new int[1]; GLES10.glGetIntegerv(GLES10.GL_MAX_TEXTURE_SIZE, maxTextureSize, 0); Log.d("MaxTexture", " Texture Size: " + maxTextureSize[0]); I get the following output: Texture Size: 16384   Whoa that's huge. I can use a 16384 x 16384 size bitmap to generate a texture, that's great. I also queried the canvas objects width and height with this code: Log.d("MaxCanvas", "Max width " + canvas.getMaximumBitmapWidth() + " Max height: " + canvas.getMaximumBitmapHeight()); And I get the following output:   MaxCanvas? Max width 32766 Max height: 32766   At first I assumed that these values would be equal, so now I know I need to use the lesser of the two to composite and generate my textures. Fair enough.   The problem is when I go to generate my bitmap/texture I use the value I get from the GLES10 method and I get the following error:       Process: com.bytevisor.pitch, PID: 13607     java.lang.OutOfMemoryError: Failed to allocate a 1073741836 byte allocation with 16777216 free bytes and 229MB until OOM             at dalvik.system.VMRuntime.newNonMovableArray(Native Method)             at android.graphics.Bitmap.nativeCreate(Native Method)             at android.graphics.Bitmap.createBitmap(Bitmap.java:939)             at android.graphics.Bitmap.createBitmap(Bitmap.java:912)             at android.graphics.Bitmap.createBitmap(Bitmap.java:879)             at com.bytevisor.pitch.framework.imp.ImageComposer.<init>(ImageComposer.java:41)             at com.bytevisor.pitch.main.AssetManager.load(AssetManager.java:93)             at com.bytevisor.pitch.main.screen.menuScreen.<init>(menuScreen.java:59)             at com.bytevisor.pitch.main.MainActivity.getStartScreen(MainActivity.java:14)             at com.bytevisor.pitch.framework.imp.Game.onSurfaceCreated(Game.java:95)             at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1509)             at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1248)     So I'm not sure where I'm going wrong here. I can hard code the width and height to 2048 no problem, but when I use values that I get from the GL10ES method I get nowhere. Help!    
  8. horrificmonster

    Model View Controller

    Thanks for the information. I think I should probably take some of these patterns with a grain of salt eh?
  9. horrificmonster

    Model View Controller

    I've been reading up on design patterns and one of the topics I have come across is model view controller. It sounds great, and I've been able to separate the model from the view fairly easily. I have three classes at the moment, WorldModel, WorldView and WorldController. WorldModel contains all of the various states, enemies, player location and miscellaneous objects. WorldModel has a 'getObjects()' method that returns an Array that the WorldView class can cycle through and render each object. Easy peasy.   This is all well and good, but I'm having trouble separating the WorldModel from WorldController. Let's say I have a player class instance in WorldModel. I need to move the player as the game progresses, so I'm assuming I need to do something like WorldController.movePlayer(float x, float y). Should this controller class method access the Model class members directly? Everything I've read says this is a no-no, so I should use methods from the Model class instead. Well, what is the point of even using the Controller class in the first place if I'm just going to hand this off to the Models methods anyway? Should the controller be a nested class within the model so that it can access the data directly from the inside?   I suppose I could use some clarification on the concept of model view controller in general. Like how much control should a model have over it's own state?   Any light shedding would be greatly appreciated!
  10. Hi All, I've been fumbling forward with trying to put together an Android game. Most of the things I can get to work, but I'd really love to learn best practices if possible. For instance, I can get my background to generate just fine. But when I look at the code I just KNOW there is a better way to do this... Essentially I use a hash function to take the x and y coordinates to generate a consistently reproducible level backwards and forwards. I generate a for loop to draw assets randomly every 80x80 pixels. Here is the code:     //Spritebatcher will start an array of floats to store for each asset that is added that OpenGL will use to draw to the screen. The startBatch method will bind the texture that is passed to it so each asset from that point onward will be using a region of this texture atlas. spriteBatcher.startBatch(AssetManager.texture); //Loop and increment on the x axis to draw a mountain randomly based on the seed and modulus of the result. The assets start drawing to the screen from a base X value (world.sceneStartX); int len = 8; for (int i = 0; i < len; i++) { random.setSeed((long) (i * 80 + world.sceneStartX)); if (random.nextInt() % 5 == 4) { int mountainIndex = (int) (i * 80 + world.sceneStartX) % 2; spriteBatcher.addDrawable(i * 80 + world.sceneStartX,85, AssetManager.mountainType[mountainIndex].width,AssetManager.mountainType[mountainIndex].height, AssetManager.mountainType[mountainIndex]); //i++; } } spriteBatcher.endBatch(); for (int i = 0; i < len; i++) { spriteBatcher.addDrawable(i * 80 + world.sceneStartX, 30, 80, 80, AssetManager.grassType[(int) (i * 80 + world.sceneStartX) % 2]); } //This follows the same concept as the mountains, but increments on the y axis as well to draw clouds. for (int i = 0; i < len; i++) { for(int j = 0;j<len;j++) { random.setSeed((long)((i*80+world.sceneStartX))); random2.setSeed(random.nextInt() + (long)((j*80+world.sceneStartY))); if (random2.nextInt() % 10 ==8 && j*80+world.sceneStartY>100) { int cloudIndex = (int) ((i * 80 + world.sceneStartX)+(j * 80 + world.sceneStartY)) % 3; spriteBatcher.addDrawable(i * 80 + world.sceneStartX, j*80+world.sceneStartY, AssetManager.cloudType[cloudIndex].width, AssetManager.cloudType[cloudIndex].height, AssetManager.cloudType[cloudIndex]); //i++; } } } //Mostly the same as the cloud generation. for (int i = 0; i < len; i++) { for(int j = 0;j<len;j++) { random.setSeed((long)((i*80+world.sceneStartX)+10)); random2.setSeed(random.nextInt() + (long)((j*80+world.sceneStartY))); if (random2.nextInt() % 10 ==8 && j*80+world.sceneStartY>100) { spriteBatcher.addDrawable(i * 80 + world.sceneStartX, j*80+world.sceneStartY, 50, 50, AssetManager.hummingbirdAnimation.getFrame(deltaTime)); //i++; } } } //If the player reaches a certain point, increase the base x axis value so the assets will start building from there. if (world.player.position.x - (camera.frustrumWidth / 2) - 61 >= world.sceneStartX) { world.sceneStartX += 80; } spriteBatcher.endBatch();         And this is how I have been dynamically generating my levels. It just seems very.. messy. I've thought about creating a 'Chunk' class that takes a seed and generates a 320x480 chunk of the level, but inside of this class it will be just as messy as this and I feel like it's akin to sweeping this under the rug. There has to be an elegant solution to this and I'm hoping someone can point me in the right direction. Extra points if you can point me to a book or resource that teaches how to tackle these sorts of problems in games! Please let me know if you have any questions about the code above. Any help or hints would be much appreciated. Thanks!!!
  11. horrificmonster

    Encoding Metadata in Bitmaps

    Yeah, now that you mention it, I think having a separate file might be a better idea. I could have an xml file that I can read in that will encode where the file is located, along with metadata I need. That sounds like a great solution! That way I can create files and reference them in my game without having to mess with texture regions, etc... Just the ID I assign to each asset in the XML file...   Thanks for the help!
  12. horrificmonster

    Encoding Metadata in Bitmaps

    Isn't there a limit to how large a texture can be? I think it's 1024 or 2048 or something? Is there a way you know of a way to generate a bitmap with header data that I can read into my game somehow?   Also, thanks for your replies!
  13. horrificmonster

    Encoding Metadata in Bitmaps

    Well at the current point in time I do have a texture atlas that I use. Problem is, the images I will need in the texture atlas will depend on what the player chooses. Say the player can choose between 3 different characters to play as. If I use static texture atlases, then I will need to have a texture atlas for my character sprite sheets, one for my level assets, etc... I was thinking it might be possible to create one texture atlas on the fly based on what the player chooses that way I'm not binding and debinding textures multiple times per frame. I was thinking if I'm generating one unique texture for each level then it would save me those extra calls while the level is being run.   So my idea was, create my bitmaps for each unique sprite, encoding the metadata for each sprite in the bitmap. Then, in the program at runtime, generate a texture atlas based on what the player needs to play the level. The program would read the individual bitmaps, composite them into a master bitmap, then load a texture from there. Also I will need a list to tell me where everything is. This list will be generated while the bitmaps are being loaded into memory, telling where texture regions are for each asset.   The reason why I decided to do things this way is because this static texture is starting to drive me crazy. When I have to add sprites change or remove sprites that in turn changes the texture regions and I have to change that as well. Seems like it might be a better programming practice to do this programmatically. I'm trying to be as lazy as possible here, hah.
  14. Hello all,   First off, I should say that I'm working on an Android game with target > 2.2  and OpenGLES 1.0.   Here's the situation: Each level will use a class to load all of the images it needs into one bitmap that I will load into a texture for OpenGLES to bind to. I figure this is a good way to go, since dynamically creating my textures will help reduce calling the gl to swap textures. I want this code to be reusable, so I would like to write a class that reads the asset type, number of frames, etc... from the bitmap files, instead of hard coding all of this into my asset loading code. That way, when I decide I need a new asset, I just encode the asset data into the new bitmap I'm creating and I don't need to touch the code. I'd like to learn how to encode the data in my bitmaps, and read this data from the bitmap. Problem is, I'm not sure where to start. I'd like to learn how to do this myself instead of rely on a library. This game I'm programming is as much a learning exercise as anything else.   Any suggestions?     Thanks!
  15. horrificmonster

    How are Endless Levels Designed?

    I'm working on generating an endless level game on Android. I've got the framework up and running and some physics, and now I'm getting to the point to where I need to think about how I'm going to generate and track the world around the player. I've been thinking about this for a while and I'm just not sure what to do from here. I was thinking I could just randomly generate objects and the background of the level as the player progresses. But the player needs to be able to move backward as well. If that is the case then I need to keep track of all of my objects, and in an endless game, doesn't that mean I'm going to have a metric ton of objects in memory? How do I store the data for the ground, trees, mountains and whatnot? What is the best practice for this sort of thing? My initial thought is, the grass, trees and mountains are inconsequential to the game, they're just background objects. I'm thinking I can set up a pattern that repeats for these (tree1,tree2,tree3 in an array that uses a formula to figure out where each object needs to be loaded based on where the player x,y coord is), and save myself some grief with keeping track of those. Is that pretty standard? What do I do about keeping track of enemies/objstacles/powerups? Also right now I'm using a camera class that uses OpenGL orthographic projection to change the Frustrum to follow the player around the map. I've seen some articles say keep the player in one spot and move everything around the player, and some say the camera is good as well. What is the best practice for this?   And lastly, if anyone knows of any good resources that are worth a read for a budding game developer, I'd love to hear about them. I've found a lot of material on frameworks, languages and whatnot, but nothing that tackles specific problems that developers run into and best practices for those sorts of things. Sort of a standard practices for various game types book? Nothing code specific, just ideas on how to tackle various problems.   Thanks!
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net 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!