|
Thread Rules 1. This is not a "do my homework for me" thread. If you have specific questions, ask, but don't post an assignment or homework problem and expect an exact solution. 2. No recruiting for your cockamamie projects (you won't replace facebook with 3 dudes you found on the internet and $20) 3. If you can't articulate why a language is bad, don't start slinging shit about it. Just remember that nothing is worse than making CSS IE6 compatible. 4. Use [code] tags to format code blocks. |
On October 09 2013 04:08 NB wrote: Im trying to make a simple snake game. Do i really need to make 3 threads (mainDisplay, snakeRun, input) for it or there is a way that i could get away with 2? It's quite uncommon to use several threads in gaming applications. Usually it's just one thread doing one loop per frame, first handling input, then updating entities, then drawing to the screen. Why have you decided to do it threaded, it makes it far more complicated.
|
Because if i combine my input and display into 1 thread, which is what im doing right now, I cant get an input delay system running that prevent cases where User input is too fast.
For example: Here is my snake running to the right
-------------- -ooo>----- --------------
what would happen is that if the user input UP->LEFT faster than my frame rate, the snake will run backward through itself -_-.
|
On October 09 2013 04:42 NB wrote: Because if i combine my input and display into 1 thread, which is what im doing right now, I cant get an input delay system running that prevent cases where User input is too fast.
For example: Here is my snake running to the right
-------------- -ooo>----- --------------
what would happen is that if the user input UP->LEFT faster than my frame rate, the snake will run backward through itself -_-.
Rather than a key press corresponding to changing the position of the player, have a key press correspond to putting the player in the "move state" which in turn is checked during your update phase. In short, your game loop should look like this:
def game_loop(): while True: process_input(...) update_world(...) render_world(...)
In process_input, you detect, e.g., an up keypress. When you detect this, you toggle a piece of state in your player data structure that says "move up". Then in update_world, you check this state and if it is enabled, move the player up. This makes player actions locked to the frame rate of the game.
|
On October 09 2013 04:42 NB wrote: Because if i combine my input and display into 1 thread, which is what im doing right now, I cant get an input delay system running that prevent cases where User input is too fast.
For example: Here is my snake running to the right
-------------- -ooo>----- --------------
what would happen is that if the user input UP->LEFT faster than my frame rate, the snake will run backward through itself -_-. You have to protect yourself from that on your own part. You should probably set it up so that the snake can only update its position once per frame or is disallowed from moving back through itself, which would let a user change his mind midframe. This is easy enough to implement, one way would be to have the snake object keep track of the desired direction for the next update and simply disallow setting it pointing towards the tail.
Using threads will not only make your game slower (unless you have a good reason to use threads, the overhead is far worse than the gains) it will also make it far harder to work with since you will have to make sure it's synchronized.
|
On October 09 2013 05:14 Tobberoth wrote:Show nested quote +On October 09 2013 04:42 NB wrote: Because if i combine my input and display into 1 thread, which is what im doing right now, I cant get an input delay system running that prevent cases where User input is too fast.
For example: Here is my snake running to the right
-------------- -ooo>----- --------------
what would happen is that if the user input UP->LEFT faster than my frame rate, the snake will run backward through itself -_-. You have to protect yourself from that on your own part. You should probably set it up so that the snake can only update its position once per frame or is disallowed from moving back through itself, which would let a user change his mind midframe. This is easy enough to implement, one way would be to have the snake object keep track of the desired direction for the next update and simply disallow setting it pointing towards the tail. Using threads will not only make your game slower (unless you have a good reason to use threads, the overhead is far worse than the gains) it will also make it far harder to work with since you will have to make sure it's synchronized. Im trying to avoid having the 1move-1frame solution though. I really want it to work in real time with an manual input lag. This is only a test game for me to make bigger applications and such implementation is needed.
yes i do use move_state. it looks something like this
thread(update_world(&x, ...)); thread.start;
def game_loop(): while True: x=process_input(...) render_world(...)
x is my move state. This means that my snake will move completely independent compare to the display/input. Right now my input is set up like above because its how SFML handle it(as far as i know). I would like to set it up so that my input run in a separated thread so when i insert a delay, it does not interfere with my render.
|
On October 09 2013 05:24 NB wrote:Show nested quote +On October 09 2013 05:14 Tobberoth wrote:On October 09 2013 04:42 NB wrote: Because if i combine my input and display into 1 thread, which is what im doing right now, I cant get an input delay system running that prevent cases where User input is too fast.
For example: Here is my snake running to the right
-------------- -ooo>----- --------------
what would happen is that if the user input UP->LEFT faster than my frame rate, the snake will run backward through itself -_-. You have to protect yourself from that on your own part. You should probably set it up so that the snake can only update its position once per frame or is disallowed from moving back through itself, which would let a user change his mind midframe. This is easy enough to implement, one way would be to have the snake object keep track of the desired direction for the next update and simply disallow setting it pointing towards the tail. Using threads will not only make your game slower (unless you have a good reason to use threads, the overhead is far worse than the gains) it will also make it far harder to work with since you will have to make sure it's synchronized. Im trying to avoid having the 1move-1frame solution though. I really want it to work in real time with an manual input lag. This is only a test game for me to make bigger applications and such implementation is needed. yes i do use move_state. it looks something like this thread(update_world(&x, ...)); thread.start;
def game_loop(): while True: x=process_input(...) render_world(...)
x is my move state. This means that my snake will move completely independent compare to the display/input. Right now my input is set up like above because its how SFML handle it(as far as i know). I would like to set it up so that my input run in a separated thread so when i insert a delay, it does not interfere with my render. You should still do it in one thread, that doesn't mean anything have to be dependent on the frame rate. What you should do is count the milliseconds for each loop and use the delta time with your updates. That way you can set up stuff like speed etc to tweak the game. At 60 or even 30 frames per second, the input will feel instantaneous. If you want it slower than that, nothing is stopping you from running input logic fewer times per second than the display update, but really, your game shouldn't be that dependent on such considerations because it makes it far harder to change later.
|
update_world.speed = 500ms/loops game_loops.speed = 8ms/loops (input_check + rendering) (~roughly 120fps)
these are my numbers right now. Obviously if i raise the Update_world.speed into 200ms/loops it would be pretty hard for human input to 'break' the game but I also need my snake to run at small speed early on.
Correct me if im wrong but are you suggesting that I should manually decrease the render_world.speed to match my update_world.speed?
|
On October 09 2013 05:59 NB wrote: update_world.speed = 500ms/loops game_loops.speed = 8ms/loops (input_check + rendering) (~roughly 120fps)
these are my numbers right now. Obviously if i raise the Update_world.speed into 200ms/loops it would be pretty hard for human input to 'break' the game but I also need my snake to run at small speed early on.
Correct me if im wrong but are you suggesting that I should manually decrease the render_world.speed to match my update_world.speed? No, there is no reason to do that. What you would normally do, in a game, is cap the input and update to 25-30 frames per second, while not capping the drawing at all. That's what lets games run really fast and smooth on fast computers without messing up the gameplay, physics etc.
It's important to note though, that human input shouldn't ever be problematic. You check to see what the human is pressing, then you tell the model (the actual gameplay world) what the human wants you do to. Then you let the world update itself accordingly. Let's say the human spams keys, up->left->up->left over and over. That shouldn't matter to the world because it only updates at set intervals, it doesn't let the human input a bunch of stuff which happens at once (because that would break most games, think of a 2D RPG like Dragons Quest... if you press left 10 times in one frame when you're next to a wall, you shouldn't be allowed to walk through the wall).
Think of it like components. Your handleInput method is like a controller, the update_world is like a separate world which only reacts, and the drawing is just a representation of that world at a point in time. If you want to simulate input lag, that code should probably be in the controller, but this shouldn't affect the world. You don't need threads to simulate this.
Keep in mind, 60 frames per second is less than 17 milliseconds per frame. A human won't notice if it's 1 thread or 10 (though 10 will probably slow things down). Threads don't actually run things in parallel (unless it's long computations optimized for running on another core), but they actually takes turns. So you're just giving control of what happens when to the computer, when you can keep all that control to yourself.
The main point here is that you shouldn't let your world (IE your snakes speed) be dependent on user input, it should be dependent on world rules. If the world states that the snake can only move 100px per second, or change its direction once per frame, the amount of user input should not be allowed to break this, and this is solved quite easily by simply supplying delta time on each update. So lets say you set your snake speed to 100. In snakeUpdate(clock.elapsedMilliseconds) you would simply do something like snake.Position += speed * elapsedMilliseconds.AsSeconds. This would mean that no matter how slow or fast the game is going, the snake will still only move 100px per second, the frame rate will just decide how choppy it looks.
|
On October 05 2013 09:22 berated- wrote:Show nested quote +On October 05 2013 01:36 Frigo wrote:On October 04 2013 12:16 sluggaslamoo wrote:On October 04 2013 10:34 Frigo wrote: For example there is an MMORPG implementing component based entities in a relational database with strict concurrency guarantees and a nice ability to scale. Can you say the same thing about OOP based solutions? OOP based solutions can not be stored in arbitrary storages, they do not scale.
I don't know what paradigms have to do with database performance. A lot actually. ECS translates rather directly to either relational tables or key-value stores, it completely circumvents the object-relational mismatch and the expensive operations to translate between objects and database entries. The way I implemented my component storage is essentially a Map<Class<? extends Component>, Map<int, Component>>, in other words for every component type I have associations between entity ids and component instances of the particular component type. The choice of the inner map implementation is important, since there is a tradeoff involved between space and performance. I have two implementations for it, one is a simple ArrayList<T extends Component> with optimal lookup performance, the other is a Trove TIntObjectHashMap which stores sparse maps in a space efficient manner while still providing excellent performance. In my case entity ids are pooled int values, meaning they are reused and are always between [0..n), but Trove maps would work with non-pooled long values too, and is probably preferred when replication and synchronization is taken into account. It is not hard to see the parallels with databases: the first choice corresponds to storing components in a huge table where columns are component types and rows are entity ids, cells are either null or component instances, the second choice corresponds to a key-value database with component type and entity id as key(s). It is simple and flexible enough to conform to the addressing method of a particular key-value store or document database. It is also easy to see that it would not take much work to actually store all these components in an in-memory, or cached on-disk database, with all the nifty features modern databases offer. In my case I would just create a new ComponentStorage implementation. However at the moment database backed components are not the direction I am going. However you should look at CouchDB which is a document oriented database (as opposed to a relational database) which scales much better than RDBMS through replication and the fact that it doesn't use tables. Especially for games, relational databases are an inferior solution even just performance wise, not to mention how much easier it is to maintain code-wise.
For the record you normally use an ODM with CouchDB which is object oriented. A few months ago I was trying to sort through the chaos that is open source nosql databases and found LevelDB and LMDB among a few others to be interesting enough to consider (for other purposes as well). Basically what would be nicest is a fast key-value store or document database that is either a cached on-disk db or a memory mapped on-disk db. Replication and such features are nice but they introduce another tradeoff and additional problems so I don't want to deal with that for quite a long while. Can you please explain "expensive operations to translate between objects and database entries"? Are you speaking to trying to persist large object graphs in a normalized manner? Or? Also, how is Map<Class<? extends Component>,Map<int, Component>> not object oriented? If you need a fast key value store though, redis or memcached might prove helpful.
Object-relational mapping. Look it up.
That specific Java based component storage is a matter of convenience, I'm using the .class of the various components, for example Position.class, as keys rather than strings, for example "Position". I could have written Object instead of Component, it would still be the same. And it's far fetched to call that OOP, just because components derive directly from Object. But all of this is beside the point: as long as the entities (the "int" part of that line) do not form form a class hierarchy, implement custom logic, or hardwire together, it is fine.
An SQL or key-value storage would do as well for storing components. As I said, one MMORPG implemented entities and components in a relational database with transactions as the update logic. There is a .ppt or .pdf somewhere on the net detailing their way, but I can not find it.
|
On October 09 2013 05:59 NB wrote: update_world.speed = 500ms/loops game_loops.speed = 8ms/loops (input_check + rendering) (~roughly 120fps)
these are my numbers right now. Obviously if i raise the Update_world.speed into 200ms/loops it would be pretty hard for human input to 'break' the game but I also need my snake to run at small speed early on.
Correct me if im wrong but are you suggesting that I should manually decrease the render_world.speed to match my update_world.speed?
If you REALLY want input "has it happens" instead of having it synced with frames (i.e. if you click during the render function it won't register) my option would be this:
char x; int i=0; while (gameRunning) { if(keydown()){ x=keypressed(); } if (i==20) //20 ms between each frame { changeWorld(x); render(); x="";i=0; } i++; sleep(1); }
It's been a long time since I coded a game but I think there was actually a much better way to do this where you dont need the sleep(1) + iteration counter, instead you would use a keyPress function that would tell the last key pressed since the last call (it's basically what my code does but on a much lower level that doesnt require sleep(1) i believe). That would be pretty useful in a snake game
|
The input system is one or more callbacks putting input actions into a concurrent queue.
Game logic drains the contents of the queue, transforms the input actions into game actions (too many layers of logic to explain here), updates the game world accordingly, and clones the game world into a(n atomic) reference for the renderer.
The renderer grabs this game world clone and renders it.
Input system is event driven, game logic should be capped at reasonable simulation speeds (5..30 fps), renderer can go as fast as it wants. Use schedulers.
Otherwise systems can be single threaded apart from these boundaries. Game logic in particular should definitely be single threaded.
The headache is not this, the headache is networked games and interpolated rendering.
|
On October 08 2013 18:32 goody153 wrote:Show nested quote +On October 08 2013 13:19 tec27 wrote:On October 08 2013 06:20 NB wrote:On October 07 2013 12:39 goody153 wrote: hi everyone,
i am not really good and just an noob-to-okish programmer .. i wanted to try game development on android .. do you guys have any advice for me ?
and also what language should i be learning ? what are the most important topics i should focus on ? from what i know java is used in making android but thats all i know for now ..
i already made games out of applet using java and also a game web-based using javascript .. so i have a little bit of experience and idea how ..
oh dont quote me on this bc i dont have a lot of on hand experience in android app making.I looked into it in the past as well as having my roommate's gf working in Twitter's android apps department. Here is a few things: 1/ Compatibility is a big issue for android. Each devices has their own attribute and you have to accommodate for all of them. It is advised that you should start with making apps for apple devices since they are more uniformed. 2/ For mobile devices in general, java, ruby on rails and basic knowledge about html/css and even a bit of SQL are needed. Most smartphone apps has interaction with web and database(loading ads or google store for example).... 3/ Experience android devices yourselves. Bluestack is a good emulator for android on window that im using. Nexus 4 and Nexus 7 are dirt cheap that you could get your hand on. The Android apps market is unexplored and dirt poor of good apps if you compare it to Apple's store. And there is a good reason for that: its easier to make apple apps and people who use apple devices are more likely to pay for apps. 4/ Lastly, for gaming in mobile device in general, just keep in mind that the input system sucks ass. Unless you are making a very simple game and expecting to make graphic your selling point, then you gona have to spend a lot of design time into the input interaction. Your advice is basically all bad. 1) Android devices are certainly less uniform than Apple devices, but its not that hard to make an app that looks decent across a large part of the population. While the market is fragmented, there are a few devices that take up the lion's share of the market. Namely, the Samsung flagships (S2, S3, S4, Note 2, Note 3) and Nexus devices. Android also has good mechanisms for scaling layouts and resources across device sizes and resolutions, so if you stick to best practices (like specifying sizes in DPs, etc.), its not a problem. Its certainly not a reason to avoid the platform altogether and work on iOS apps. The major pain point is working with Gingerbread and below, but if you're just developing apps as a hobby you can just choose a higher minimum version and sidestep the problem completely. 2) Ruby on Rails? What the fuck does that have to do with Android? Java is the only really necessary piece here. SQL knowledge can be a nice to have, depending on how much data you are going to be storing and what your persistence requirements are. Android has its own layout and style system that's written in XML. Its *somewhat* similar to HTML, but not really. Overall its fairly easy to get started with. Depending on what your app is doing, you may want to develop an API server that your app can talk to, but you can write this in whatever language you damn well please. Or you could use something like Parse to make your life easier. 3) Using something like Bluestacks is a bad idea if you're using it to develop your app and trying to test it on hardware that you don't actually have. That sort of software targets running apps on a PC, not simulating actual hardware interactions. Use the actual emulator that's provided with Android, it works fine and is actually targeted at developers. But overall, developing on an emulator will be mostly frustrating, so buy a cheap Android device or two and use those for your day-to-day work, only going to the emulator when you absolutely need to. 4) Completely game/application type dependent. Obviously you should design applications that work well on the devices they run on. To reply to you directly, goody: - Learn Java - Learn OpenGL ES 2.0 (if you have more JS experience than Java, you could play around with WebGL in the browser, which has the same API) - Check out the Android developers traininig site: http://developer.android.com/training/index.html i am more knowledgeable in java than in JS .. one more thing i wanted to ask .. aside from OpenGL ES 2.0 or WebGL ..any other library that is easier to use and integrate unto the android program later ? since i am just making a Tower Defense game its really emphasized on the graphics much .. and also i have been doing sort of research .. what version of android should i work on ? some told me to work on lower versions like 2.0 to 2.5 ... somewhere around that and in the database part of the development .. would my knowledge on php help on that matter ? or its a separate thing anyways thanks for the great advice tec27  2.3.x is the last version of Android with major version 2, so I'm not quite sure where you're getting your information from You should avoid Gingerbread (2.3.x/API 10) imo, as its crufty and old. The APIs and OS have improved substantially since then. Personally I would just pick whatever version you development device is running, ideally some version of JellyBean (4.1.x, 4.2.x, 4.3.x, API 16+). You should accept that whatever you're working on now will never be a major hit in the app store and therefore trying to "maximize your market" is a useless endeavor. Just focus on learning Android and seeing if you like it.
Knowledge of PHP will likely not be very helpful, unless you're talking about actually interfacing with databases. Android apps that use databases typically use SQLite, but I would think that for a simple game, you won't be touching databases at all.
|
On October 09 2013 06:09 Tobberoth wrote:Show nested quote +On October 09 2013 05:59 NB wrote: update_world.speed = 500ms/loops game_loops.speed = 8ms/loops (input_check + rendering) (~roughly 120fps)
these are my numbers right now. Obviously if i raise the Update_world.speed into 200ms/loops it would be pretty hard for human input to 'break' the game but I also need my snake to run at small speed early on.
Correct me if im wrong but are you suggesting that I should manually decrease the render_world.speed to match my update_world.speed? No, there is no reason to do that. What you would normally do, in a game, is cap the input and update to 25-30 frames per second, while not capping the drawing at all. That's what lets games run really fast and smooth on fast computers without messing up the gameplay, physics etc. It's important to note though, that human input shouldn't ever be problematic. You check to see what the human is pressing, then you tell the model (the actual gameplay world) what the human wants you do to. Then you let the world update itself accordingly. Let's say the human spams keys, up->left->up->left over and over. That shouldn't matter to the world because it only updates at set intervals, it doesn't let the human input a bunch of stuff which happens at once (because that would break most games, think of a 2D RPG like Dragons Quest... if you press left 10 times in one frame when you're next to a wall, you shouldn't be allowed to walk through the wall). Think of it like components. Your handleInput method is like a controller, the update_world is like a separate world which only reacts, and the drawing is just a representation of that world at a point in time. If you want to simulate input lag, that code should probably be in the controller, but this shouldn't affect the world. You don't need threads to simulate this. Keep in mind, 60 frames per second is less than 17 milliseconds per frame. A human won't notice if it's 1 thread or 10 (though 10 will probably slow things down). Threads don't actually run things in parallel (unless it's long computations optimized for running on another core), but they actually takes turns. So you're just giving control of what happens when to the computer, when you can keep all that control to yourself. The main point here is that you shouldn't let your world (IE your snakes speed) be dependent on user input, it should be dependent on world rules. If the world states that the snake can only move 100px per second, or change its direction once per frame, the amount of user input should not be allowed to break this, and this is solved quite easily by simply supplying delta time on each update. So lets say you set your snake speed to 100. In snakeUpdate(clock.elapsedMilliseconds) you would simply do something like snake.Position += speed * elapsedMilliseconds.AsSeconds. This would mean that no matter how slow or fast the game is going, the snake will still only move 100px per second, the frame rate will just decide how choppy it looks.
Very accurate, except this:
Threads don't actually run things in parallel (unless it's long computations optimized for running on another core), but they actually takes turns. So you're just giving control of what happens when to the computer, when you can keep all that control to yourself.
In a symmetric multiprocessing (SMP) system, the kernel will schedule both threads simultaneously. If they have contention for a common object, say a common global variable, it will depend on the system how it is handled, but likely, this wouldn't be felt by the user, as worst case it would be as bad as a single threaded application.
In this case, you could keep your input loop as a separate thread polling for much more often than the world updates, but this wouldn't give you any advantage over a single threaded approach as the overhead to poll if a key has been pressed is low enough that it wouldn't slow your frame down by any noticeable amount.
As many modern processors have many cores or hyperthreading, SMP is becoming more and more prevalent, so it's no longer necessarily true that threads have a computational overhead. They still have a memory overhead, as each thread needs it own stack, but you're unlikely to run into that outside of embedded systems.
|
On October 09 2013 06:26 Frigo wrote:Show nested quote +On October 05 2013 09:22 berated- wrote:On October 05 2013 01:36 Frigo wrote:On October 04 2013 12:16 sluggaslamoo wrote:On October 04 2013 10:34 Frigo wrote: For example there is an MMORPG implementing component based entities in a relational database with strict concurrency guarantees and a nice ability to scale. Can you say the same thing about OOP based solutions? OOP based solutions can not be stored in arbitrary storages, they do not scale.
I don't know what paradigms have to do with database performance. A lot actually. ECS translates rather directly to either relational tables or key-value stores, it completely circumvents the object-relational mismatch and the expensive operations to translate between objects and database entries. The way I implemented my component storage is essentially a Map<Class<? extends Component>, Map<int, Component>>, in other words for every component type I have associations between entity ids and component instances of the particular component type. The choice of the inner map implementation is important, since there is a tradeoff involved between space and performance. I have two implementations for it, one is a simple ArrayList<T extends Component> with optimal lookup performance, the other is a Trove TIntObjectHashMap which stores sparse maps in a space efficient manner while still providing excellent performance. In my case entity ids are pooled int values, meaning they are reused and are always between [0..n), but Trove maps would work with non-pooled long values too, and is probably preferred when replication and synchronization is taken into account. It is not hard to see the parallels with databases: the first choice corresponds to storing components in a huge table where columns are component types and rows are entity ids, cells are either null or component instances, the second choice corresponds to a key-value database with component type and entity id as key(s). It is simple and flexible enough to conform to the addressing method of a particular key-value store or document database. It is also easy to see that it would not take much work to actually store all these components in an in-memory, or cached on-disk database, with all the nifty features modern databases offer. In my case I would just create a new ComponentStorage implementation. However at the moment database backed components are not the direction I am going. However you should look at CouchDB which is a document oriented database (as opposed to a relational database) which scales much better than RDBMS through replication and the fact that it doesn't use tables. Especially for games, relational databases are an inferior solution even just performance wise, not to mention how much easier it is to maintain code-wise.
For the record you normally use an ODM with CouchDB which is object oriented. A few months ago I was trying to sort through the chaos that is open source nosql databases and found LevelDB and LMDB among a few others to be interesting enough to consider (for other purposes as well). Basically what would be nicest is a fast key-value store or document database that is either a cached on-disk db or a memory mapped on-disk db. Replication and such features are nice but they introduce another tradeoff and additional problems so I don't want to deal with that for quite a long while. Can you please explain "expensive operations to translate between objects and database entries"? Are you speaking to trying to persist large object graphs in a normalized manner? Or? Also, how is Map<Class<? extends Component>,Map<int, Component>> not object oriented? If you need a fast key value store though, redis or memcached might prove helpful. Object-relational mapping. Look it up. That specific Java based component storage is a matter of convenience, I'm using the .class of the various components, for example Position.class, as keys rather than strings, for example "Position". I could have written Object instead of Component, it would still be the same. And it's far fetched to call that OOP, just because components derive directly from Object. But all of this is beside the point: as long as the entities (the "int" part of that line) do not form form a class hierarchy, implement custom logic, or hardwire together, it is fine. An SQL or key-value storage would do as well for storing components. As I said, one MMORPG implemented entities and components in a relational database with transactions as the update logic. There is a .ppt or .pdf somewhere on the net detailing their way, but I can not find it.
I didn't need for you to explain object relational mapping, I was asking for you to explain why you consider it an expensive operation but then talk more saving "entities" to other types of persistence. I didn't understand why you would clarify the expensive only in the form of the object relational mapping.
Also, I understand how hashmaps work, and maybe to your surprise even realize that you are using a class reference as the key! Components aren't just deriving from object, there are objects that are deriving from components. Where do you personally draw the line between OOP and ECS? 2 layer heirarchies = good, 3 layers and you're doing it wrong?
Lastly, I'm not worried about what persistence layer you want to use. Ribbing you about you using an OO language in an OO way and then refusing to call it OOP is good enough for me. I was simply suggesting some fast key value stores if you really wanted to look into some.
|
There exists something coined the "slot map" around my school which is best for looking up game objects. The only thing on the internet similar (that I know of) is Noel Llopis's HandleManager. Since we're on the topic of kv lookups for game objects specifically (yes, even in a ECS) this simple data structure is ideal. I suggest checking it out.
Edit: And no it isn't slow, nor a bottleneck. The lookup cost is one if branch and an array index operation. I recently did a lecture on this sort of thing: slides here.
|
On October 09 2013 07:53 CecilSunkure wrote:There exists something coined the "slot map" around my school which is best for looking up game objects. The only thing on the internet similar (that I know of) is Noel Llopis's HandleManager. Since we're on the topic of kv lookups for game objects specifically (yes, even in a ECS) this simple data structure is ideal. I suggest checking it out. Edit: And no it isn't slow, nor a bottleneck. The lookup cost is one if branch and an array index operation. I recently did a lecture on this sort of thing: slides here.
I know this under the name of entity id pooling. I have it implemented as a component storage strategy. Two main issues with it in this context is that it takes up at least (component types * entities) references which is a lot of memory, and it does not play nice with serialization and networking. I prefer non-changing int or long entity ids and fast primitive map implementations like Trove or Colt. They are more memory efficient and the performance difference is negligible.
|
On October 09 2013 06:09 Tobberoth wrote:Show nested quote +On October 09 2013 05:59 NB wrote: update_world.speed = 500ms/loops game_loops.speed = 8ms/loops (input_check + rendering) (~roughly 120fps)
these are my numbers right now. Obviously if i raise the Update_world.speed into 200ms/loops it would be pretty hard for human input to 'break' the game but I also need my snake to run at small speed early on.
Correct me if im wrong but are you suggesting that I should manually decrease the render_world.speed to match my update_world.speed? No, there is no reason to do that. What you would normally do, in a game, is cap the input and update to 25-30 frames per second, while not capping the drawing at all. That's what lets games run really fast and smooth on fast computers without messing up the gameplay, physics etc. It's important to note though, that human input shouldn't ever be problematic. You check to see what the human is pressing, then you tell the model (the actual gameplay world) what the human wants you do to. Then you let the world update itself accordingly. Let's say the human spams keys, up->left->up->left over and over. That shouldn't matter to the world because it only updates at set intervals, it doesn't let the human input a bunch of stuff which happens at once (because that would break most games, think of a 2D RPG like Dragons Quest... if you press left 10 times in one frame when you're next to a wall, you shouldn't be allowed to walk through the wall). Think of it like components. Your handleInput method is like a controller, the update_world is like a separate world which only reacts, and the drawing is just a representation of that world at a point in time. If you want to simulate input lag, that code should probably be in the controller, but this shouldn't affect the world. You don't need threads to simulate this. Keep in mind, 60 frames per second is less than 17 milliseconds per frame. A human won't notice if it's 1 thread or 10 (though 10 will probably slow things down). Threads don't actually run things in parallel (unless it's long computations optimized for running on another core), but they actually takes turns. So you're just giving control of what happens when to the computer, when you can keep all that control to yourself. The main point here is that you shouldn't let your world (IE your snakes speed) be dependent on user input, it should be dependent on world rules. If the world states that the snake can only move 100px per second, or change its direction once per frame, the amount of user input should not be allowed to break this, and this is solved quite easily by simply supplying delta time on each update. So lets say you set your snake speed to 100. In snakeUpdate(clock.elapsedMilliseconds) you would simply do something like snake.Position += speed * elapsedMilliseconds.AsSeconds. This would mean that no matter how slow or fast the game is going, the snake will still only move 100px per second, the frame rate will just decide how choppy it looks. small problems though:
first of all let me show you how SFML draw a circle(code copied from there tutorial at http://www.sfml-dev.org/tutorials/2.1/start-vc.php)
#include <SFML/Graphics.hpp>
int main() { sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!"); sf::CircleShape shape(100.f); shape.setFillColor(sf::Color::Green);
while (window.isOpen()) { sf::Event event; while (window.pollEvent(event)) { if (event.type == sf::Event::Closed) window.close(); }
window.clear(); window.draw(shape); window.display(); }
return 0; }
As you can see, the event handling and the rendering process is both under the same root "window" and I just found out that each thread could only have 1 window activated and that goes both way. This means that if i somehow put a delay on my event handling, it will delay my render too.
2. I totally understand your point on how world_update should be a reactive process which response to the input function. But there is a reason why I am making Snake: the world_update process is automated. The snake is basicly a bot and you only gives it directions, not driving it. This means that my Updater will be automated. The speed of which it will be updating is also dynamic which depends on the level of the game. This means that at the very first level where the Updater is slow, there will be holes between which could create opening for human input. As this is the case, I want a dynamic lag variable that adjust according to the Updater.Speed variable.
3. The main reason why im trying this practice out is because I read one of the articles about super meat boy devs. Apparently one of them was really upset with how modern platformers handling the inputs so they built their own event handler WITH an artificial lag into some certain action. I am really interested in such design concept and the idea of having the flexibility to customize my own input system, catering it to my own games. So yes I really want input lag to work.
|
On October 09 2013 17:39 NB wrote:Show nested quote +On October 09 2013 06:09 Tobberoth wrote:On October 09 2013 05:59 NB wrote: update_world.speed = 500ms/loops game_loops.speed = 8ms/loops (input_check + rendering) (~roughly 120fps)
these are my numbers right now. Obviously if i raise the Update_world.speed into 200ms/loops it would be pretty hard for human input to 'break' the game but I also need my snake to run at small speed early on.
Correct me if im wrong but are you suggesting that I should manually decrease the render_world.speed to match my update_world.speed? No, there is no reason to do that. What you would normally do, in a game, is cap the input and update to 25-30 frames per second, while not capping the drawing at all. That's what lets games run really fast and smooth on fast computers without messing up the gameplay, physics etc. It's important to note though, that human input shouldn't ever be problematic. You check to see what the human is pressing, then you tell the model (the actual gameplay world) what the human wants you do to. Then you let the world update itself accordingly. Let's say the human spams keys, up->left->up->left over and over. That shouldn't matter to the world because it only updates at set intervals, it doesn't let the human input a bunch of stuff which happens at once (because that would break most games, think of a 2D RPG like Dragons Quest... if you press left 10 times in one frame when you're next to a wall, you shouldn't be allowed to walk through the wall). Think of it like components. Your handleInput method is like a controller, the update_world is like a separate world which only reacts, and the drawing is just a representation of that world at a point in time. If you want to simulate input lag, that code should probably be in the controller, but this shouldn't affect the world. You don't need threads to simulate this. Keep in mind, 60 frames per second is less than 17 milliseconds per frame. A human won't notice if it's 1 thread or 10 (though 10 will probably slow things down). Threads don't actually run things in parallel (unless it's long computations optimized for running on another core), but they actually takes turns. So you're just giving control of what happens when to the computer, when you can keep all that control to yourself. The main point here is that you shouldn't let your world (IE your snakes speed) be dependent on user input, it should be dependent on world rules. If the world states that the snake can only move 100px per second, or change its direction once per frame, the amount of user input should not be allowed to break this, and this is solved quite easily by simply supplying delta time on each update. So lets say you set your snake speed to 100. In snakeUpdate(clock.elapsedMilliseconds) you would simply do something like snake.Position += speed * elapsedMilliseconds.AsSeconds. This would mean that no matter how slow or fast the game is going, the snake will still only move 100px per second, the frame rate will just decide how choppy it looks. small problems though: first of all let me show you how SFML draw a circle(code copied from there tutorial at http://www.sfml-dev.org/tutorials/2.1/start-vc.php) #include <SFML/Graphics.hpp>
int main() { sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!"); sf::CircleShape shape(100.f); shape.setFillColor(sf::Color::Green);
while (window.isOpen()) { sf::Event event; while (window.pollEvent(event)) { if (event.type == sf::Event::Closed) window.close(); }
window.clear(); window.draw(shape); window.display(); }
return 0; }
As you can see, the event handling and the rendering process is both under the same root "window" and I just found out that each thread could only have 1 window activated and that goes both way. This means that if i somehow put a delay on my event handling, it will delay my render too. 2. I totally understand your point on how world_update should be a reactive process which response to the input function. But there is a reason why I am making Snake: the world_update process is automated. The snake is basicly a bot and you only gives it directions, not driving it. This means that my Updater will be automated. The speed of which it will be updating is also dynamic which depends on the level of the game. This means that at the very first level where the Updater is slow, there will be holes between which could create opening for human input. As this is the case, I want a dynamic lag variable that adjust according to the Updater.Speed variable. 3. The main reason why im trying this practice out is because I read one of the articles about super meat boy devs. Apparently one of them was really upset with how modern platformers handling the inputs so they built their own event handler WITH an artificial lag into some certain action. I am really interested in such design concept and the idea of having the flexibility to customize my own input system, catering it to my own games. So yes I really want input lag to work.  You're still going about this the completely wrong way. Everything is in the same window because that's how you make games, that's what makes sense. Just because that extremely simple tutorial doesn't implement any timing doesn't mean you can't. You need to read up on how to create proper game loops: http://www.koonsolo.com/news/dewitters-gameloop/ There is literally no problem in adding delay to your handling of inputs without it affecting your rendering, you just have to program it yourself. Just add a counter which counts the amount of milliseconds each loop and only when it reaches a cap do you actually handle the input. You can literally tweak the input lag down to the milliseconds without using threads. Just because you don't want to handle input every frame doesn't mean you have to put it outside of the loop, you just need to add a conditional.
2. This is how it works in all wellprogrammed games, that was my point. Pressing left doesn't move the character left, it tells the world to move the character left and the game does it according to its own rules. There's still no need for threads at any point. I honestly don't see where you're having any form of problem with this, you shouldn't have to edit your input logic at all just because the snakes speed changes, you shouldn't change the updater speed either. You're not making the snake faster, you're making the game update faster, which makes no sense.
3. Again, you don't need threads for input lag. Just program it. Trust me, the odds that the Meat Boy programmer meant you should use threads in game loops is minimal.
How about this, you tell me exactly what kind of input lag you're going for with an example, and I'll tell you how it can be implemented without this whole threads updating shit at different speeds. Is it input lag in the sense that you want the snake to change direction a second after you press the left button, for example?
|
On October 09 2013 06:55 tec27 wrote:Show nested quote +On October 08 2013 18:32 goody153 wrote:On October 08 2013 13:19 tec27 wrote:On October 08 2013 06:20 NB wrote:On October 07 2013 12:39 goody153 wrote: hi everyone,
i am not really good and just an noob-to-okish programmer .. i wanted to try game development on android .. do you guys have any advice for me ?
and also what language should i be learning ? what are the most important topics i should focus on ? from what i know java is used in making android but thats all i know for now ..
i already made games out of applet using java and also a game web-based using javascript .. so i have a little bit of experience and idea how ..
oh dont quote me on this bc i dont have a lot of on hand experience in android app making.I looked into it in the past as well as having my roommate's gf working in Twitter's android apps department. Here is a few things: 1/ Compatibility is a big issue for android. Each devices has their own attribute and you have to accommodate for all of them. It is advised that you should start with making apps for apple devices since they are more uniformed. 2/ For mobile devices in general, java, ruby on rails and basic knowledge about html/css and even a bit of SQL are needed. Most smartphone apps has interaction with web and database(loading ads or google store for example).... 3/ Experience android devices yourselves. Bluestack is a good emulator for android on window that im using. Nexus 4 and Nexus 7 are dirt cheap that you could get your hand on. The Android apps market is unexplored and dirt poor of good apps if you compare it to Apple's store. And there is a good reason for that: its easier to make apple apps and people who use apple devices are more likely to pay for apps. 4/ Lastly, for gaming in mobile device in general, just keep in mind that the input system sucks ass. Unless you are making a very simple game and expecting to make graphic your selling point, then you gona have to spend a lot of design time into the input interaction. Your advice is basically all bad. 1) Android devices are certainly less uniform than Apple devices, but its not that hard to make an app that looks decent across a large part of the population. While the market is fragmented, there are a few devices that take up the lion's share of the market. Namely, the Samsung flagships (S2, S3, S4, Note 2, Note 3) and Nexus devices. Android also has good mechanisms for scaling layouts and resources across device sizes and resolutions, so if you stick to best practices (like specifying sizes in DPs, etc.), its not a problem. Its certainly not a reason to avoid the platform altogether and work on iOS apps. The major pain point is working with Gingerbread and below, but if you're just developing apps as a hobby you can just choose a higher minimum version and sidestep the problem completely. 2) Ruby on Rails? What the fuck does that have to do with Android? Java is the only really necessary piece here. SQL knowledge can be a nice to have, depending on how much data you are going to be storing and what your persistence requirements are. Android has its own layout and style system that's written in XML. Its *somewhat* similar to HTML, but not really. Overall its fairly easy to get started with. Depending on what your app is doing, you may want to develop an API server that your app can talk to, but you can write this in whatever language you damn well please. Or you could use something like Parse to make your life easier. 3) Using something like Bluestacks is a bad idea if you're using it to develop your app and trying to test it on hardware that you don't actually have. That sort of software targets running apps on a PC, not simulating actual hardware interactions. Use the actual emulator that's provided with Android, it works fine and is actually targeted at developers. But overall, developing on an emulator will be mostly frustrating, so buy a cheap Android device or two and use those for your day-to-day work, only going to the emulator when you absolutely need to. 4) Completely game/application type dependent. Obviously you should design applications that work well on the devices they run on. To reply to you directly, goody: - Learn Java - Learn OpenGL ES 2.0 (if you have more JS experience than Java, you could play around with WebGL in the browser, which has the same API) - Check out the Android developers traininig site: http://developer.android.com/training/index.html i am more knowledgeable in java than in JS .. one more thing i wanted to ask .. aside from OpenGL ES 2.0 or WebGL ..any other library that is easier to use and integrate unto the android program later ? since i am just making a Tower Defense game its really emphasized on the graphics much .. and also i have been doing sort of research .. what version of android should i work on ? some told me to work on lower versions like 2.0 to 2.5 ... somewhere around that and in the database part of the development .. would my knowledge on php help on that matter ? or its a separate thing anyways thanks for the great advice tec27  2.3.x is the last version of Android with major version 2, so I'm not quite sure where you're getting your information from  You should avoid Gingerbread (2.3.x/API 10) imo, as its crufty and old. The APIs and OS have improved substantially since then. Personally I would just pick whatever version you development device is running, ideally some version of JellyBean (4.1.x, 4.2.x, 4.3.x, API 16+). You should accept that whatever you're working on now will never be a major hit in the app store and therefore trying to "maximize your market" is a useless endeavor. Just focus on learning Android and seeing if you like it. Knowledge of PHP will likely not be very helpful, unless you're talking about actually interfacing with databases. Android apps that use databases typically use SQLite, but I would think that for a simple game, you won't be touching databases at all. so i should go for the new versions ? .. i am worried that the game that i will develop will not be compatible in some of the android devices especially cheap android phones that why i aim for the lower versions .. no worries i am actually just learning to develop in android for fun not aiming for money or anything ... i am still a university student so i dont think i have huge amount of time i can spare to those sort of stuff that requires investing too much time and money you know hehe .. it just turns out that i have some time to spare that is not allocated in either playing/watching games or doing school works .. and i am fascinated with the game development i find it really fun ..
since i have a little experience in coding in java and familiar with applets/MIDP(i know nobody uses this shit anymore) .. i thought i could learn android since it involves java hehe ..
|
On October 09 2013 16:18 Frigo wrote:Show nested quote +On October 09 2013 07:53 CecilSunkure wrote:There exists something coined the "slot map" around my school which is best for looking up game objects. The only thing on the internet similar (that I know of) is Noel Llopis's HandleManager. Since we're on the topic of kv lookups for game objects specifically (yes, even in a ECS) this simple data structure is ideal. I suggest checking it out. Edit: And no it isn't slow, nor a bottleneck. The lookup cost is one if branch and an array index operation. I recently did a lecture on this sort of thing: slides here. I know this under the name of entity id pooling. I have it implemented as a component storage strategy. Two main issues with it in this context is that it takes up at least (component types * entities) references which is a lot of memory, and it does not play nice with serialization and networking. I prefer non-changing int or long entity ids and fast primitive map implementations like Trove or Colt. They are more memory efficient and the performance difference is negligible. Oh yeah it totally wouldn't do well for networking right out of the box. Also it doesn't take up typeCount * entities, it can be done in a way that shares slots for multiple types. Type safety can also be forgone as a memory tradeoff. Maybe you should read the code before judging.
Also do you links to the two names you referenced?
|
|
|
|
|
|