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

how to do this in c++

6 posts in this topic

hi,

i've been using this simple OO approach with rather simple code of determining if buildings have access between each other, in my game. But the problem is that it's quite clumsy way of doing OO and i think there's better solution in doing this in c++ but i can't remember what? The problem with this code is that there's possibility of infinite loop if i make some mistake in adding more classes that need this check.

 

so can you make a better OO solution for this check (code below)? 

 

 


class Bridge: public BaseBuilding
{
// return true if This building can be accessed from building b
bool canAccessFrom(BaseBuilding & b)
{
 if(b.canAccessFrom(*this)) // use the code in the other class if any...
return true;

return false;
}

};

class House: public BaseBuilding
{

bool canAccessFrom(BaseBuilding & b)
{
 return this->isOnSameLevel(b);
}

};
 

 

thanks. i hoipe i was able to explain what the problem is.

Edited by heh65532
0

Share this post


Link to post
Share on other sites

Buildings are game objects that exist in the world. Buildings are not the only object that exists in the world. The building should know what world it belongs to.

Individual game objects should know nothing about routing and navigation of the world. That isn't their responsibility.

The world should usually maintain the collection of objects within it, and it should also work with a routing system.

Perhaps it will look something like:

Route r = World.CreateRouteToObject( this, pDestinationBuilding );if(r.IsValid()){  activeUnit.SetRoute(r);  // Use the route}else{  activeUnit.ShowRouteFailure(); // Make the unit play its annoyed animation and sound }

thanks frob. So you say better OO approach is to let the world logic tell what accessibility there is between buildings? the reason for each building to have this information is because if there's a wooden bridge then humans can travel across it, but heavy donkey carts cannot because the bridge might collapse so they need to use stone bridge instead. 

every time i add new type of these buildings the pathing possibilities increase.

so i might be moving the conditional code outside the class but that seems to require keeping a list of class vs class accessibilities.

0

Share this post


Link to post
Share on other sites

So you say better OO approach is to let the world logic tell what accessibility there is between buildings? the reason for each building to have this information is because if there's a wooden bridge then humans can travel across it, but heavy donkey carts cannot because the bridge might collapse so they need to use stone bridge instead.
every time i add new type of these buildings the pathing possibilities increase.
so i might be moving the conditional code outside the class but that seems to require keeping a list of class vs class accessibilities.

Are you remembering to program to interfaces, and also to use composition?

Everything that exists in the world is a game object.

Some game objects are portals. They should implement a portal interface, or if your design prefers, they should have a portal component.

I'm guessing your portal would be like ours. A portal has some number of lanes (usually 1), and the routing system automatically routes near the portal, waits for a lane to become free, marks the lane as in use, then travels across it. Only certain units can travel across particular lane types. There is an animation that plays (very similar to the basic walking cycle) when a unit travels between the portal endpoints. And finally, you can place multiple portals together end-to-end and have them work continuously.

We have many kinds of portals. They include bridges, ramps, stairs, doors, and elevators.

For us, we simply add a portal component to a game object, fill in a few functions that the interface requires such as the portal type and the animation names, and routing automatically picks up whatever new portal type we added.
0

Share this post


Link to post
Share on other sites

I'm guessing your portal would be like ours. A portal has some number of lanes (usually 1), and the routing system automatically routes near the portal, waits for a lane to become free, marks the lane as in use, then travels across it. Only certain units can travel across particular lane types. There is an animation that plays (very similar to the basic walking cycle) when a unit travels between the portal endpoints. And finally, you can place multiple portals together end-to-end and have them work continuously.

We have many kinds of portals. They include bridges, ramps, stairs, doors, and elevators.

For us, we simply add a portal component to a game object, fill in a few functions that the interface requires such as the portal type and the animation names, and routing automatically picks up whatever new portal type we added.

 

that sounds like a good way. but the thing is i added access logic to each building so they can tell the pathfinder in which various ways they can be traveled through. for example there maybe a tower with one door on ground level and two doors at the top leading outside where a wall can be. So the tower needs to tell pathfinder the ground door can be used if there's ground and not water for example or some other obstacle and the top doors can be used if there's some connection like walls/platform next to the doors. 

this seems to require rather complex set of portals. so i might use some kind of portal component system or try to do better OO design. 

Edited by heh65532
0

Share this post


Link to post
Share on other sites

So the tower needs to tell pathfinder the ground door can be used if there's ground and not water for example or some other obstacle and the top doors can be used if there's some connection like walls/platform next to the doors

 

I'm not sure the why the tower would care that there are walls or water blocking the doors. It should just say "I have a door that opens here, a door that opens here, and a door that opens here", and provide some description of the kind of objects that can travel through the tower.

 

The pathfinder would then be responsible for examining each of those routes, and checking to see if there is a wall or water blocking the way (as it would be if there were open land immediately outside each of those doors, but which was then discovered to be walled or watered in a short distance from the doors).

 

Also, you can reduce the complexity of your multiple dispatch problem if you can attempt to categorize your buildings and other objects as to the kind of things they let pass through.

1

Share this post


Link to post
Share on other sites

So the tower needs to tell pathfinder the ground door can be used if there's ground and not water for example or some other obstacle and the top doors can be used if there's some connection like walls/platform next to the doors

 

I'm not sure the why the tower would care that there are walls or water blocking the doors. It should just say "I have a door that opens here, a door that opens here, and a door that opens here", and provide some description of the kind of objects that can travel through the tower.

 

The pathfinder would then be responsible for examining each of those routes, and checking to see if there is a wall or water blocking the way (as it would be if there were open land immediately outside each of those doors, but which was then discovered to be walled or watered in a short distance from the doors).

 

Also, you can reduce the complexity of your multiple dispatch problem if you can attempt to categorize your buildings and other objects as to the kind of things they let pass through.

 

yes i very much agree. problem is with the complexity. but i'm going to use common attributes for each object (both path traveler and geometry) to determine in single function can the path go through an tile.

this can get probably quite complex but at least there's no duplicated code or any other problems. 

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