51

Go with the second approach, simply due to the fact that you can introduce new resource types or items at any time without having to rewrite or update code (data driven development). Edit: To elaborate a bit more on why this is in general good practice, even if you're 100% sure some value won't ever change. Let's take the console game example mentioned in ...


38

First of all, it's way less clutter. If you have a position, a velocity and an acceleration, that's already 6 variables you have to deal with, 9 in 3d. Secondly, and this is the most important part, it grants you access to many ways to use or change them. For instance, getting the length of the vector, normalizing it, adding them together, dot product, ...


31

One quick way to get key-value pairs in Unity's inspector is to define a serializable entry class, and then use an array or List<> of them. eg... public class SpellAnimationMap : ScriptableObject { [System.Serializable] public class SpellAnimationEntry { public Spell spell; public AnimationClip animation; } public ...


29

A rule of thumb is that you use different classes when objects require different code and instances of the same class when the objects only require different values. When the resources have different game mechanics which are unique to them, it might make sense to represent them with classes. For example, when you have Plutonium which has a half-life time ...


27

At first you see that your commands are in the form of a list, so your first instinct might be to recreate that structure, and each dwarf will run through that list in sequence. What I suggest though is to break the list into steps, with each step having prerequisite(s), and then you run the entire command in reverse. Let me demonstrate with an example: ...


14

I would like to add there are two extra options: Interface: you can consider it if the resource class would be just a "storage" for 5 integers and each other entity would have different logic regarding resources (e.g. player spend/loot, city produces resource). In that case you might not want a class at all - you merely wanted to expose that some entity has ...


14

Compare the function signatures of both RotatePoints versions. Lone variables: void RotatePoints( float *out_x, int x_interleave_out, const float *in_x, int x_interleave_in, float *out_y, int y_interleave_out, const float *in_y, int y_interleave_in, float angle, int count ) { float s = sinf(angle); float c = cosf(...


11

2D hexagonal maps are a representation of spheres packed in a flat (2D) tray, with each hex centred on the equivalent sphere, and allow distances between cells to be determined to workable (for gaming purposes anyway) accuracy, just by counting the number of hex cells through which you step. The equivalent 3D representation is the face-centred cubic (FCC)/...


11

If you can make sequences pretty general, there's not much of a spaghetti code. In case of deliveries e.g.: WorkTask operates with a WorkPlan. Workplan says what kind of resource unit must pick, from what kind of house, using which walk animation, using which work animation, time to work and all such details. So in the end WorkTask might look like: Find %...


11

Readability > Writeability I feel like it's just slow me down and barely has any benefit other than organizing your code. You are correct in that it (slightly) slows you down writing that code. However, you write it once in the beginning and from then on everytime you come back you are going to read it. So optimizing the reading speed will do much more ...


9

Tiles and icons (even in UIs like window systems) are often in a size like 16x16 or 24x24 to make it easier to modify the tiles. Most times the tile size is a multiple of 8 because of the folowing reasons. It is relatively easy to shrink a tile with the size 32x32 to 16x16 by simply putting 4 pixels together (e.g. create the median/average of the 4 pixels). ...


9

Is there some advantage to having each attribute laid out contiguously in memory? It's better for cache locality of data access. Memory access is slowest part of all modern computing systems. As memory buses pull in multiple bytes in "cachelines" and most modern CPUs will prefetch memory that it detects are being accessed contiguously, keeping data that is ...


8

Operator overloading. Vector v3 = v2 + v1; There is now only one place in your code where you have to write, test and debug vector addition, as opposed to tens, hundreds or thousands. Obviously vector addition is an overly simplistic example, but there are more complex vector operations and the same applies to those too.


7

Create an intermediary table that maps Pokemon to learnable skills: Now you can select all the learnables for a Pokemon by name: SELECT LearnableSkills.ID FROM LearnableSkills, PokemonLearnables, Pokemon WHERE LearnableSkills.ID = PokemonLearnables.LearnableID AND PokemonLearnables.PokemonID = Pokemon.ID AND Pokemon.Name = 'byte56' Or by ID: SELECT ...


6

Database reads are usually via network and from hard-drive. That means database queries will always take a few ms, no matter how simple they are. Databases can get faster with in-memory techniques and smart database designs with good indexing concepts, but their speed is often still insufficient for real-time processing. Blocking your process while a ...


5

I would probably start with the following schema: Slot (ID, CharacterID, SlotID, ItemID) where Slot is the name of the table ID is the table's primary key CharacterID is a foreign key that points to the character SlotID is the slot's ID going from 1 to 64 (or 0 to 63, or whatever) ItemID is a foreign key that points to the item (ID of a specific weapon, ...


5

Various graph representations exist. Yours is an adjacency list with explicit vertices and implicit edges: Each vertex stores its adjacent vertices, each of which implies a directed edge to it. In the above, blue squares are vertex objects, arrows are references vertex A's list of vertices is [ B ] vertex B's list of vertices is [ A, C ] vertex C's list of ...


5

So this is basicaly topographical sorting problem. You have a graph, each node is a task that needs to be done, and some nodes depend on some other nodes (this is represented by an edge in the graph from depending node to the node it depends on). You want to do all the tasks, so you need to produce SOME ordering of the nodes that is topographicaly OK (the ...


5

This is very nice example of problem suited for A* algorithm. I will not go into details how to implement A* here as it has been done better before and this very easy to find, however this is how I would apply A* for your problem: As you can see, there is only a limited number of states that you can "move" to using single swap (14 for this case if I am not ...


5

Do the simplest thing that works, especially early on. If you've ever seen videos of triple-A titles in alpha, you'll know how slow / buggy they are. This is normal; in fact, it's desirable. And it's often because they used the naive solution to problems. Agile development philosophy states Refactor Mercilessly; I couldn't agree more, from experience. ...


5

Building on the answer from @congusbonus, if you are committed to using a single variable in an array as you have shown, you can define each combination in such a way that encodes each direction as a single bit in a bitmask: int T = 1; int L = 2; int B = 4; int R = 8: int TL = T | L; ... for (each room){ int exits = exitsList[this_room]; if (exits ...


5

First of all, consider if it is actually necessary to break down the world into units of storage. 32x16x32x16x16x16 = 67,108,864 blocks. When each block is a 2 byte integer representing the type-ID, your world is just 128MB of data. All but the most low-end platforms should be able to handle that in-memory. But let's assume that you already tried that and ...


4

You should consider using a plain 2d-array or alternatively an array of rooms, where each room is a 2d-array or a grid. A grid would looks something like this: The player is the yellow dot and the blocks are the green ones. if the player is the light gray square, you only need to check for blocks that around that square area. This saves you the time of ...


4

Actually, after thinking about it for a bit, here's what my solution would be for both disk and memory storage; a mock-up in JSON: { "map_segments": [ ["upper_left", "top", "top", "upper_right"], ["left", "empty", "town_center", "right"], ["left", "shopping_area", "player_house", "right"], ["left", ...


4

new answer: In the real world, since this field is not densely populated, simply tell the characters to move in the desired direction and once they approach an obstacle, to go clockwise or counter-clockwise around it (depending on which way is shorter). To improve on this, you can walk the characters towards corners instead: In the general case, you would ...


4

Generally, you want to avoid excessive hierarchy. What if a player wants to attack an object (such as a trap, or door?) How would a trap attack a player? What about environmental hazards? I would suggest an entity-component system over inheritance here. Give everything that has health a Health component, and give everything that can attack a Weapon ...


4

Disclaimer: artemis-odb dev here. -Changing the Entity System, i know of Artemis, but it would be great if you could point me at something else for Java if you know a library that does it better. I'm not sure whether you're referring to vanilla artemis or artemis-odb, but the latter improves on performance considerably with regards to mutating entities. ...


4

Given only the sparse information you've supplied, and assuming that when creating a red edge, you wish to avoid collisions against both other edges and rects (which I assume are rooms)... What you are trying to avoid are crossings. What you want (red + green loops) are cycles in graph theory. Minimum Spanning Trees are tree-graphs - that means no cycles to ...


4

It is suitable, though perhaps not ideal. First, do note that ProtoBufs are no longer state of the art in its class. Consider Cap'n Proto, Fast Buffers, or Flat Buffers. I'm personally a fan of Flat Buffers these days, but I'm sure there's already something even better out there; this is hardly a "solved" problem. For serializing game data, you ...


Only top voted, non community-wiki answers of a minimum length are eligible