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


  • Content count

  • Joined

  • Last visited

Community Reputation

286 Neutral

About jeannekamikaze

  • Rank
  1. In this tutorial, we will see one possible way to model game objects in Haskell. To do so, the tutorial proposes several design problems with increasing levels of difficulty. For each of these problems, a solution in C++ is presented first and then potential Haskell alternatives are discussed. By the end, we will have seen how to dodge subtyping and dynamic dispatch in the design of game objects by making use of the close relationship between objects and closures. The information presented in the following sections is not new, but if you are new to functional programming you might nevertheless find it worthwhile. Finally, it is worth noting that some experience with C++ and some background in object-oriented programming are assumed. Problem 1: An Initial Game Object Suppose we are building a game. It is quite natural to think of the objects in a game as just that, game objects. As a starting point, let's say that in our game there are two types of objects: apples and bananas. Nevertheless, we do not want to limit ourselves to just these two types of objects, since we might decide to add new ones later on. In the object-oriented paradigm, we would throw in a base class, say, GameObject, from which particular types of objects such as Apple and Banana would derive. This would allow us to decouple the rest of the game code from these specific types, giving us the ability to add new types of objects at a later stage without modifying existing code and therefore satisfying the open/closed principle. The following code snippet illustrates this concept: class GameObject { public: virtual void render () const = 0; }; class Apple : public GameObject { public: void render () const { cout :t render render :: GameObject -> IO () > render banana banana This might seem rather obvious at this point. However, further problems will become more complicated and will require that we keep in mind this idea that record fields are really functions that take records as arguments, so this is a good place to bring it up. Finally, the above solution better mimics the C++ version of the code by allowing us to add new game objects without modifying the GameObject data type and therefore satisfying the open/closed principle. For instance, we can now add oranges by simply writing: orange = GameObject $ putStrLn "orange" Problem 2: Identifying Game Objects with Unique IDs Suppose that we now wish to go further by identifying game objects with a unique ID and outputting this ID when rendering an object. In C++, this could be modelled as follows: typedef int GoID; class GameObject { GoID _id; public: GameObject (GoID id) : _id(id) {} GoID id () const { return _id; } virtual void render () const = 0; }; class Apple : public GameObject { public: Apple (GoID id) : GameObject(id) {} void render () const { cout GameObject } banana :: GoID -> GameObject banana goid = GameObject { goID = goid , render = printf "banana: id %d\n" goid , update = const $ banana goid } type Level = Int type Elapsed = Float apple :: Level -> Elapsed -> GoID -> GameObject apple level elapsed goid = GameObject { goID = goid , render = printf "apple: id %d, level %d\n" goid level , update = \dt -> let elapsed' = elapsed + dt in if elapsed' >= 5.0 then apple (level+1) (elapsed' - 5.0) goid else apple level elapsed' goid } The following example illustrates the above solution. Notice that apples are only updated when more than 5 seconds have elapsed, whereas bananas remain static: > :t render render :: GameObject -> IO () > :t update update :: GameObject -> Float -> GameObject > mapM_ render . take 5 $ iterate (flip update 3) (apple 1 0 17) apple: id 17, level 1 apple: id 17, level 1 apple: id 17, level 2 apple: id 17, level 2 apple: id 17, level 3 > mapM_ render . take 5 $ iterate (flip update 3) (banana 17) banana: id 17 banana: id 17 banana: id 17 banana: id 17 banana: id 17 Apple Reification Unleashed Having an actual Apple data type will make the current solution more readable and will allow us to define functions that operate on a proper Apple type rather than a losely defined set of parameters. The Apple data type could be defined as: data Apple = Apple { level :: Level , elapsed :: Float } At this point, one might argue that defining an apple as a type contradicts our argument that apples in our solutions are really functions, not proper types. The point here is that the Apple data type just captures all of the data needed to represent an apple; it is not trying to be a subtype of GameObject. The reason we do this is to allow for more readable code. For example, the apple update function can now be rewritten as: updateApple :: Apple -> Dt -> Apple updateApple (Apple level elapsed) dt = let elapsed' = elapsed + dt in if elapsed' >= 5.0 then Apple (level+1) (elapsed' - 5.0) else Apple level elapsed' Had we not defined the Apple type, the updateApple function would take one argument for each apple attribute like in the solution to problem 4. This grows rather unreadable and unmaintainable as the representation of an apple becomes more complex, which is why we define the Apple data type. Moving on, we can redefine the apple function itself to act directly on an Apple value and make use of the updateApple function we have just defined: apple :: Apple -> GoID -> GameObject apple a goid = GameObject { goID = goid , render = printf "apple: id %d, level %d\n" goid (level a) , update = flip apple goid . updateApple a } Full source code with the above changes and additions follows: import Text.Printf type GoID = Int type Dt = Float data GameObject = GameObject { goID :: GoID , render :: IO () , update :: Dt -> GameObject } type Level = Int type Elapsed = Float data Apple = Apple { level :: Level , elapsed :: Elapsed } updateApple :: Apple -> Dt -> Apple updateApple (Apple level elapsed) dt = let elapsed' = elapsed + dt in if elapsed' >= 5.0 then Apple (level+1) (elapsed' - 5.0) else Apple level elapsed' apple :: Apple -> GoID -> GameObject apple a goid = GameObject { goID = goid , render = printf "apple: id %d, level %d\n" goid (level a) , update = flip apple goid . updateApple a } banana :: GoID -> GameObject banana goid = GameObject { goID = goid , render = printf "banana: id %d\n" goid , update = const $ banana goid } The following example illustrates this last solution. Note that it is not much different from that of problem 4; it simply makes use of the new Apple type to construct an apple: > mapM_ render . take 5 $ iterate (flip update 3) (apple (Apple 1 0) 17) apple: id 17, level 1 apple: id 17, level 1 apple: id 17, level 2 apple: id 17, level 2 apple: id 17, level 3 > mapM_ render . take 5 $ iterate (flip update 3) (banana 17) banana: id 17 banana: id 17 banana: id 17 banana: id 17 banana: id 17 Conclusions Many times, we might feel tempted to think of new entities as subtypes of a more general type. This, however, might not be the best solution to a given problem and does not properly map to languages lacking subtyping. In Haskell, we can use plain functions to encode these new entities as closures and to provide a mechanism to build values of that more general type that act as the subtypes we were first trying to define. This effectively dodges any use of subtyping and yields code that is equally extensible. When we are doing functional programming, we have to stop thinking of functions as just a mere means of computation; functions in a functional language will often go all the way and beyond.
  2. It is open source, it's just not free.
  3. I've got the point now, and avoiding colliding mesh data with other mesh data solves my design issue. In any case, I guess you'd want to collide bounding volumes with mesh data. Like say if you have a car and a stop light, a box-box test wouldn't let you drive the car under the stoplight, however a box-mesh test would, so I guess the proper thing would be to go for a box-box test first to eliminate false positives and then go for a box-mesh test if the first test passes, which isn't as expensive as a mesh-mesh collision since that would imply considering every pair of triangles.
  4. Well this isn't about ray tracing but you gave me an idea which I'll discuss in case anyone is interested. The problem arises when colliding two objects A and B which share mesh data. Instead of doing a per-triangle collision, I'll collide A's triangles with B's bounding box, which is already precise enough and faster than a triangle-to-triangle collsiion. To do so I'll calculate the inverse of A's world matrix and bring B's bounding box to A's local space as you suggested, where the box-triangle collision will take place. I think that should do it :), thanks for your idea.
  5. Hello. I've got a design issue that I just ran into and I'd like to discuss it here to see if anyone who has had a similar situation can help me out. I just noticed the description got kind of lengthy so please bear with me. So far I've got this class called "Model" which holds model data - vertices, indices, and normals. Apart from that I have an "Entity" class, which amongst other things has a member variable which is a pointer to a Model instance; this way, all entities of the same kind share the same geometric data. So, for example, to draw a bunch of trees in the scene, I'd have several instances of Entity and a single Model for the tree. Each tree Entity would apply its transformation matrix and then call the Model's draw method. So far so good. Now say I want to perform a collision test between two trees. First I'd build a bounding box around each one of them, test for box collision, and if the box test passes then I'd perform a more accurate per-triangle one. However, I have a problem: the Model class holds the tree's data in local space - i.e. I don't have the vertex data for each tree in world space. What I thought about the bounding box is the following: Each tree Entity would have a box which is updated every time the tree entity is transformed; the box would first be calculated in local space and then I'd apply the Entity's particular transformation matrix over the box to transform it to world space. This way each tree would have its own bounding box in world space ready for collision. However, what shall I do with vertices? I need each of the tree's vertices in world space to perform an accurate collision after the box one, and I don't have these. Letting the Entity have an updated copy of its vertices in world space would kind of defeat the purpose of having a Model instance shared between all entities of the same kind. Transforming each of the entity's vertices to world space before performing the collision test would bring a performance hit if several collision tests are carried since these would be recalculated for every test. I'm not sure if I'm being clear enough so please ask for clarifications if you have the time/will to help me out. Perhaps I should take a whole different approach. Your feedback is all welcome :)
  6. Ah! Thanks. Lots of happiness for you and your loved ones :).
  7. Hello, I am having some trouble with glTexImage2D. What happens is it segfaults every now and then (about 9 out of 10 times). This is what I am doing essentially: GLuint ID; char data[64*64]; glEnable(GL_TEXTURE_2D); glGenTextures(1, &ID); glBindTexture(GL_TEXTURE_2D, ID); // Segfault here --> glTexImage2D(GL_TEXTURE_2D, 0, 4, 64, 64, 0, GL_RGBA, GL_UNSIGNED_BYTE, data); // <-- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); ... I am checking for errors with glGetError() after glEnable, glGenTextures, and glBindTexture, and no errors turn up. Could anyone provide any light as to what might cause the problem? Thanks in advance.