Jump to content

- - - - -

on hard coded vs soft coded constants

4: Adsense

on hard coded vs soft coded constants

a recent posting of mine:

rpg/person sim, fps interface:
~100 monster types, ~250 object types, ~60 weapon types, ~45 skill types, ~200 meshes, ~300 textures, ~ 10 materials, ~100 models, ~30 animations, 2500x2500 mile game world.

models and animations are made using an in-game editor, and saved to disk. the list of models and animations to load is hard coded.

meshes (.x) and textures (.bmp or .dds) are loaded from file. the list of files to load is hard coded.

the game world is procedurally generated.

everything else is hard coded: monster types, object types, weapon types, materials, skill types, etc.

the reasoning is as follows:

1. for everything hard coded, the final values will be known constants for the final release version. so soft coding is only an aid in dialing in these "tune-able constants", such as the list of all meshes to load (the game loads everything once at program start). none of this stuff changes very much, only while dialing in the game. and it doesn't change at all once dialed in. and it never changes in versions released to the public - only in updates. granted, a zipped 2K text file list of meshes to load is smaller than a 1.2 meg zipped exe, but unless your releases are minor updates, odds are the code will change too. as always it depends on what you're doing.

2. since soft coding is not required for release, and since i have full source access, and rebuilt times are not bad, its overkill.

3. in the end, you have to "hard code" or type in this data somewhere using some syntax. if there's no difference except running faster and less code complexity, why not just do it in the native programming language? no need to learn a scripting language, no need to write hooks and calling wrappers for game engine functions so your scripts can invoke calls to the game engine, no need to find and integrate a scripting solution into the project. no slow 4gl / 5gl / scritping BS, no need to use multiple languages to code a game, and so on.

so i soft code the models and animations. they are the type of data (scales, rotations, offsets, mesh and texture ID #'s) that really scream for an editor. i mean could you imagine having to use a markup language to do this:

Posted Image

and having to picture in your head what the model looks like?

but everything else is more or less a set it one time and forget it kind of thing, unless you need to tweak stats. IE just add the info for a new whatever to the "list" or "database" when you add a new mesh, or monster type, or object type, or whatever.

so its really easiest to just use code to say essentially: monstertype[new_monster].hp=100. and be done with it.

sure you may have to go back later and tweak that "100", but only if you didn't figure out the correct value the first time. you should have the "rules" of the game figured out before you code. Posted Image

Sep 11 2013 03:11 PM

Note that i recently upgraded the Z game library to load soft coded lists of meshes, textures, model, and animations if desired.


I also upgraded the Z "engine" to load soft coded lists of target types and targets if desired.


But Caveman uses none of this (yet), for the reasons listed above.

Note: GameDev.net moderates comments.