I was thinking that the total skill points would be cached in memory local to the core dwarf data, and only updated when something is learned or forgotten; that way the vast majority of the time no calculations would be needed.
Cache only helps when the read out >> write cost. And while dwarfs are not idling, they are actually doing something at every time you refresh data of the world, and each refresh the system needs to readout the skill_level to determine the efficiency of the works dwarfs are doing, so it can advance the progress of each work(+ N%), hence I believe its best to
read the skillmap and update the cache, ONLY after a fixed counter is reach, so the operation time of
skill_read_n_writeto_cache(), can be spread. The less often you update, the more FPS, you get, otherwise, it will be lagging, but update more often, so you get more accurate reading when you view a dwarf. The rate should related to how often, a player check the skill on average. And you don't need to use a very efficient skill_level_read at first, and optimized it later, as long as the counter is large enough, OR a better idea,
it only update after a dwarf went to sleep and at the point of waking up, so this function can be tied to the wake up function, think of Oblivion 4, and other RPG game element.
As for gaining skill, there wouldn't be a situation where a dwarf 'must' gain a skill point, and the system would loop until it found an unset bit to set. attempting to gain skill would just be an 'or' operation; if the bit was already set, then nothing new is actually learned, and the fuction is done. This simulatates it getting hard and harder to discover/invent something new; just like the increasing points needed to level a skill at each level currently, and in most other games with 'levels'
Its impractical, to call gain_skill_training(), every time the world is refresh, the same reason as before, but when the point where a certain job is done, a good is produce, a hauling is in place, a session of combat course is finished, so the cost of this function which contain time consuming rand(), can be spread. Or even better, as using the sleep-learning system, that while training, the training result is only store in a cache as an index as well, and only slowly "written in" the dwarf brain while sleep at a constant rate (Oh! the dream of a dwarf, was so dwarfy), and at a much slower rate while idling, whether or not the dwarf can used out the learning index, depend one how quick a learner he is (less counter), and how many time he is idling/sleeping. So we get a legitimize reason why a dwarf is idling and what's the need of sleeping. (Or is it already been done by Toady? just using current skill update, this technique can also increase FPS as well.) Hence an idling dwarf is actually a learning dwarf not a lazy dwarf, we all misunderstood them. (If you keep pushing every dwarf to do thing, and don't let him rest/sleep he will over-load his index, and never learned anything, we can even implement a new FUN! as a dwarf been working to death
)
I also erred in saying 'bitmap', maybe I should have said 'bitmask', I wasn't thinking of a 2d grid, or a line... just raw bits. with the only presentation to the user being the same description DF does now 'Dabbling' to 'Legendary', based up the total number of set bits (by native popcount instruction, or methods from http://graphics.stanford.edu/~seander/bithacks.html#CountBitsSetParallel
As a better image to the whole picture, I would say we can call this an actual "
dwarf brainmap", and better yet, why 2d at all, it can be 3d, or higher! (your brain is not actually 3d, since area in one part of the brain, not just related to their surrounding area, but also connect to far parts of the brain, more like a 3.5d, and why neural system functioning). So certain skill is laying in one part of the brainmap (poor dwarf can only see black/white 0/1
), it's neighbor skills are the only ones can be overlapping with it, the bigger the surface area(boundary in 2d), the more skill it connected to. The volume (or area in 2d), is not positive related to the surface (boundary), an area can be like a starfish shape, with a long boundary border but a minimum area; an area like a circle is the exact opposite. And a good idea for why book should work, the eyes connected to every part of the brainmap, and a book is a "bitmask represented with dots", and the function of the eye, is actually the OR function to combine these 2 arrays.
But the mechanism I was talking about previous post setting the overlapping part, still need to be worked on, it needs to be "draw" carefully to set some correct logical overlapping in a brainskillmap. The same dots belong to a skill should gather together tightly in 2d/3d spatial positions, for the purpose of aesthetics as well as for purpose of deigned, its easier to picture them in blocks, before putting into array. Skills group like in the real brain, things like mortar function(military, hauling, mining) as larger groups first. Skills set don't have to be clustering in one continuing shapes, it can containing many areas with different shapes like in real brain. (This didn't effect the programming at all, just to the purpose of actually writing the value preset in skill_mask array, or you won't even have a place to start. Implementing them sections by sections won't generate a 2d/3d related maps, but a num_section-dimension related blocks, and looked very chaos mapping into 2d/3d plane)
!WARNING suggestions below are extra thoughts, and will cause extra costs in memory/calculationWe can even have a smart(or dumb) potions system, that magically add dots intelligence/knowledge in a dwarf, how neat. And why set a fixed size/static brainmap, it can be grown/moved. So the younger dwarf can only access a part of the whole brainmap, and his brain capacity determine the whole potential, and only get wiser from learning, but before dwarfs are old enough. Its not possible to produce a GOD-like dwarf while he is young, It has a max possible size, so to be the complete knowledge of the wold. In implementing it will need extra process to check boundary, and while get_skill_level function doesn't need to be changed, but training will need extra brain size mask types (selected regarding age and intelligence level?), Then ((BrainMap OR LearnedSkillMap) AND BrainSizeMask), to get a new BrainMap.
Even cache has a real meaning, as it represent a dwarf's shorten memory, a temporary storage, and the brainmap actually store the long-term part. We can even tweak the cache so it has 3 variables to represent a skill, the base value from updating from brainmap, and a increment as calculated from learning index cache, and the real skill efficiency is the combination of both. So a dwarf can temporarily be quicker at a short time, but not really settle down to base value in the brainmap, and its possible to lost the index cache, when the cycle of sleep(idling can help to reduce the need) is interrupt before its count to 0, and the full skill potential is not as efficient as the previous working day when he just waking up, until he actually starts working again. And we can add a "church bell" mechanics, to wake up the dwarf in an area, to interrupt their sleep and make it more FUN! (Bells have real purpose not just for FUN, since it is possible to running out of index (index count to 0), and the dwarf still sleeping, and now the dwarf is actually lazy than helpfully learning.)