• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
TheChubu

How is this usually done?

2 posts in this topic

Hi.

 

So I was wondering if there is a better way to deal with the multiple buffers/arrays/etc when I'm loading a heightmap (or other resource) because I'm producing a lot of duplicate data in the process.

 

Currently I point to the image and read it. From that I have a BufferedImage (I'm using Java) that holds all the heights.

 

That BufferedImage isn't directly usable for what I'm trying to do so I construct a vertex array out of its pixels, which is a plain array of floats (ie, XYZ-XYZ-XYZ and so on).

 

Now I read another image to get color data for each pixel (no texturing yet), again, I need to extract the data from that BufferedImage so I construct a new plain array of floats with a color per vertex (RGB-RGB-RGB and so on).

 

After that I construct an array of normals out of the vertex array I made before.

 

There I have all the data in 3 different arrays. I want an interleaved array to pass to OpenGL so I create a new array interleaving the data of the three float arrays.

 

Since OpenGL and Java don't get along that well, I also need to construct a FloatBuffer out of that interleaved array so I can pass the data to OpenGL.

 

Moreover, since I only retain the interleaved array, that's the one I'm using to get height information of the terrain to calculate the camera's height in the world. That means lots of offset this and offset that to get around the color and normal data in the array.

 

Summing up, I have massive amounts of duplicate data (two redundant BufferedImages and 3 float arrays, plus the needed FloatBuffer) while I'm loading it to only retain the interleaved array and the FloatBuffer.

 

Am I missing something important here? The garbage collector should get rid of the redundant stuff since I don't reference it anymore but it still quite a jump of used memory to load a single asset. It probably can get out of hand loading many things.

Edited by TheChubu
0

Share this post


Link to post
Share on other sites

 I would re-write to just generate the final array. Load both the heightmap and colormap images, then generate your interleaved array, normals and all.

 

 Or, you're probably going to want to have access to certain data, like the heightmap and normals, for physics purposes (assuming you're going beyond simply rendering a terrain). In that case, organize your data so that the heightmap data is easily accessible, and then generate the interleaved array. At any rate, only generate the data you will need beyond load time. Minimize the redundant data. It won't really make a difference, but it will make your code more compact, which in larger projects becomes a good thing. Doing more work with less code is what separates the newbies from the gurus.

1

Share this post


Link to post
Share on other sites

Hm, I'll refactor the methods to work inside the interleaved array with an offset and a stride then. That ought to get rid of most of the redundant data. Otherwise I'll try to use TWL's PNG decoder instead of BufferedImages if it works better.

 

I'm not too worried about the code but the whole idea of (for example) using 2Gb of ram while loading assets only to keep half of that or less once the GC kicks in.

 

For now I get the heights of the map by working inside the interleaved array. There is a DataMeshTerrain class that has a "getHeightAt" method that does the work around the array indices of the mesh (among other things). I don't know if its the most "elegant" way but it works for now.

 

Anyway, I'll still have to refactor everything again if I decide to implement a half edge structure someday biggrin.png

 

EDIT: Talking about the array. Turns up that working directly with it (interleaved or not) is kinda a mess for calculating normals. I have to write lots of boilerplate code since each corner of the map is a special case and each side of the map is a special case. Ends up beign 4 loops, one for each side, 4 directly calculated normals, one for each corner, and a single loop for the rest of the interior vertices. Its pretty fast but its like 150 or 200 lines long.

 

For doing it in a more "elegant" way I need to store some kind of adjacency data per vertex right? (so it ends up in a more simple "for each adjacent vertex do this")

Edited by TheChubu
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0