• 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.

Archived

This topic is now archived and is closed to further replies.

Glak

[java] scope help please

8 posts in this topic

I started to throw a pathfinding/attackmove demo together yesterday but I couldn''t get access to variables in other classes. I want public Square[][] terrain = new Square[10][10]; to be availible everywhere. If I put it into a particular class only the methods in that class work. I made everything public but that doesn''t seem to fix it. Note there are probably some bad decisions in how the thing is set up, but I just want it all to compile first. //first file public class TrivialApplication { World w = new World(); public static void main(String args[]) { System.out.println( "Hello World!" ); } } //second file public class Square //will not compile { public int x; public int y; public int cost; //public Square[][] terrain = new Square[20][20]; public Square(int x_, int y_, int cost_) { x=x_; y=y_; cost=cost_; } public Square() /*without this constructor Path would not compile*/ { x=-1; y=-1; cost=99; } /* here is where I need to access terrain. I tried a few differnt ways, such as the w.terrain version, a TrivialApplication.w.terrain, and a few other things, none work unless I just put terrain itself in this class. public Square[] adjacent() { Square[] adj = new Square[6]; adj[0] = w.terrain[x-1][y-1]; adj[1] = terrain[x][y-1]; adj[2] = terrain[x-1][y]; adj[3] = terrain[x+1][y]; adj[4] = terrain[x][y+1]; adj[5] = terrain[x+1][y+1]; return adj; } } //third file public class World { public Square[][] terrain = new Square[10][10]; public World() { } } //fourth file public class Path { int totalCost; public Square thisSquare; public Path nextPath; public Path(Square s, Path p) { thisSquare = s; nextPath = p; } }
0

Share this post


Link to post
Share on other sites
Okay you aren''t making your Square[][] static, that means that everytime you make a new object of the class that has Square[][], you get a new Square[][] tied to that object. You need to reference the 2D array as object.Square[][]. If you made it static, it would bind to the class, allowing you to reference it as ClassName.Square[][], or Square[][] if it''s public.

I hope that this was your problem and that this allows it to compile and run.
0

Share this post


Link to post
Share on other sites
Thanks a lot. Making it static fixed it. I tried World.terrain and it worked. What has me confused is that w.terrain didn''t work earlier when it was nonstatic.
0

Share this post


Link to post
Share on other sites
If w.terrain didn''t work and terrain was public, w probably wasn''t. You get used to it after a while, and you can spot these things as you''re writing them.
0

Share this post


Link to post
Share on other sites
I was wondering what the general design for creating the classes for a world are.
My first (failed) attempt had a base class with terrain and unit info in it. Then came a terrainmanager and unit manager. Finally i had the applet class.

did i space things out too much? I had the same prob with the static terrain level too. My last resort solution was to dump everything into a single file.

PEACE
GAZZ
0

Share this post


Link to post
Share on other sites
Also, how much performance is lost using a 2d array? When i was playing with C i could see a small, but detectable performance drop using a 2d array over a plain array. Does that same thing happen in Java??

Me and my dumb questions.

PEACE
GAZZ
0

Share this post


Link to post
Share on other sites
Jim_Ross:
thanks, that looks like the problem.


eqs:
I''m putting an x and y coordinate in each unit, try that. That way your units always know where they are. You might also want to keep some unit info in the terrain (so you can find out which units are in an area) too.
0

Share this post


Link to post
Share on other sites
quote:
Original post by eqs
Also, how much performance is lost using a 2d array? When i was playing with C i could see a small, but detectable performance drop using a 2d array over a plain array. Does that same thing happen in Java??



You lose performance in C using a dynamic 2D array because there is a double derefernce going on. In a static 2D array there''s a few more arithmetic ops and a derefernce.

In Java, how much performance is lost depends on the JVM. I believe Sunsoft''s JVM performs a triple dereference to access a member of an array. And then your 2D array is just an array of arrays so you need to triple dereference the second array that actually holds your data in order to get at the information you need. The MS JVM only perfroms a double derefernce per array. Either way you''ve got lots of memory dereferncing going on. Which is kind of slow.

On the other hand you can use a 1D array and use arithmetic operations to treat it as a 2D array, so you only lose the triple/double dereference and an add/multiply pair. So it will be slightly faster. But would it be worth the loss of code clarity?
0

Share this post


Link to post
Share on other sites
What kind of low-level dereferencing goes into using java.util.List. That''s how I store the data for my map, and migrating from a 1D array seemd to boost it alot. Actully, I create 8 new Sublists each drawing cycle and it still goes faster.
0

Share this post


Link to post
Share on other sites