This repository has been archived on 2023-10-09. You can view files and clone it, but cannot push or open issues or pull requests.
Files
blender-archive/source/blender/makesdna/intern/makesdna.c

1271 lines
32 KiB
C
Raw Normal View History

/*
* ***** BEGIN GPL LICENSE BLOCK *****
2002-10-12 11:37:38 +00:00
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
2002-10-12 11:37:38 +00:00
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
2010-02-12 13:34:04 +00:00
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
2002-10-12 11:37:38 +00:00
*
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
* All rights reserved.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL LICENSE BLOCK *****
*/
/** \file makesdna.c
* \brief Struct muncher for making SDNA.
* \ingroup DNA
2002-10-12 11:37:38 +00:00
*
* \section aboutmakesdnac About makesdna tool
2002-10-12 11:37:38 +00:00
* Originally by Ton, some mods by Frank, and some cleaning and
* extension by Nzc.
*
* Makesdna creates a .c file with a long string of numbers that
* encode the Blender file format. It is fast, because it is basically
* a binary dump. There are some details to mind when reconstructing
* the file (endianness and byte-alignment).
*
* This little program scans all structs that need to be serialized,
* and determined the names and types of all members. It calculates
* how much memory (on disk or in ram) is needed to store that struct,
* and the offsets for reaching a particular one.
*
* There is a facility to get verbose output from sdna. Search for
* \ref debugSDNA. This int can be set to 0 (no output) to some int. Higher
2002-10-12 11:37:38 +00:00
* numbers give more output.
*/
2002-10-12 11:37:38 +00:00
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include "MEM_guardedalloc.h"
#include "DNA_sdna_types.h"
#include "BLO_sys_types.h" // for intptr_t support
2002-10-12 11:37:38 +00:00
#define SDNA_MAX_FILENAME_LENGTH 255
/* Included the path relative from /source/blender/ here, so we can move */
/* headers around with more freedom. */
static const char *includefiles[] = {
2002-10-12 11:37:38 +00:00
2012-07-07 22:51:57 +00:00
/* if you add files here, please add them at the end
* of makesdna.c (this file) as well */
2002-10-12 11:37:38 +00:00
"DNA_listBase.h",
"DNA_vec_types.h",
"DNA_ID.h",
"DNA_ipo_types.h",
"DNA_key_types.h",
"DNA_text_types.h",
"DNA_packedFile_types.h",
"DNA_camera_types.h",
"DNA_image_types.h",
"DNA_texture_types.h",
"DNA_lamp_types.h",
"DNA_material_types.h",
"DNA_vfont_types.h",
2012-07-07 22:51:57 +00:00
/* if you add files here, please add them at the end
* of makesdna.c (this file) as well */
2002-10-12 11:37:38 +00:00
"DNA_meta_types.h",
"DNA_curve_types.h",
"DNA_mesh_types.h",
"DNA_meshdata_types.h",
"DNA_modifier_types.h",
"DNA_lattice_types.h",
2002-10-12 11:37:38 +00:00
"DNA_object_types.h",
"DNA_object_force.h",
"DNA_object_fluidsim.h",
2002-10-12 11:37:38 +00:00
"DNA_world_types.h",
"DNA_scene_types.h",
"DNA_view3d_types.h",
"DNA_view2d_types.h",
2002-10-12 11:37:38 +00:00
"DNA_space_types.h",
"DNA_userdef_types.h",
"DNA_screen_types.h",
"DNA_sdna_types.h",
// if you add files here, please add them at the end
// of makesdna.c (this file) as well
"DNA_fileglobal_types.h",
"DNA_sequence_types.h",
"DNA_effect_types.h",
"DNA_outliner_types.h",
2002-10-12 11:37:38 +00:00
"DNA_property_types.h",
"DNA_sensor_types.h",
"DNA_controller_types.h",
"DNA_actuator_types.h",
"DNA_sound_types.h",
"DNA_group_types.h",
"DNA_armature_types.h",
"DNA_action_types.h",
"DNA_constraint_types.h",
"DNA_nla_types.h",
"DNA_node_types.h",
Orange: - New UI element: the "Curve Button". For mapping ranges (like 0 - 1) to another range, the curve button can be used for proportional falloff, bone influences, painting density, etc. Most evident use is of course to map RGB color with curves. To be able to use it, you have to allocate a CurveMapping struct and pass this on to the button. The CurveMapping API is in the new C file blenkernel/intern/colortools.c It's as simple as calling: curvemap= curvemapping_add(3, 0, 0, 1, 1) Which will create 3 curves, and sets a default 0-1 range. The current code only supports up to 4 curves maximum per mapping struct. The CurveMap button in Blender than handles allmost all editing. Evaluating a single channel: float newvalue= curvemapping_evaluateF(curvemap, 0, oldval); Where the second argument is the channel index, here 0-1-2 are possible. Or mapping a vector: curvemapping_evaluate3F(curvemap, newvec, oldvec); Optimized versions for byte or short mapping is possible too, not done yet. In butspace.c I've added a template wrapper for buttons around the curve, to reveil settings or show tools; check this screenie: http://www.blender.org/bf/curves.jpg - Buttons R, G, B: select channel - icons + and -: zoom in, out - icon 'wrench': menu with tools, like clear curve, set handle type - icon 'clipping': menu with clip values, and to dis/enable clipping - icon 'x': delete selection In the curve button itself, only LMB clicks are handled (like all UI elements in Blender). - click on point: select - shift+click on point: swap select - click on point + drag: select point (if not selected) and move it - click outside point + drag: translate view - CTRL+click: add new point - hold SHIFT while dragging to snap to grid (Yes I know... either one of these can be Blender compliant, not both!) - if you drag a point exactly on top of another, it merges them Other fixes: - Icons now draw using "Safe RasterPos", so they align with pixel boundary. the old code made ints from the raster pos coordinate, which doesn't work well for zoom in/out situations - bug in Node editing: buttons could not get freed, causing in memory error prints at end of a Blender session. That one was a very simple, but nasty error causing me all evening last night to find! (Hint; check diff of editnode.c, where uiDoButtons is called) Last note: this adds 3 new files in our tree, I did scons, but not MSVC!
2006-01-08 11:41:06 +00:00
"DNA_color_types.h",
"DNA_brush_types.h",
Added custom vertex/edge/face data for meshes: All data layers, including MVert/MEdge/MFace, are now managed as custom data layers. The pointers like Mesh.mvert, Mesh.dvert or Mesh.mcol are still used of course, but allocating, copying or freeing these arrays should be done through the CustomData API. Work in progress documentation on this is here: http://mediawiki.blender.org/index.php/BlenderDev/BlenderArchitecture/CustomData Replaced TFace by MTFace: This is the same struct, except that it does not contain color, that now always stays separated in MCol. This was not a good design decision to begin with, and it is needed for adding multiple color layers later. Note that this does mean older Blender versions will not be able to read UV coordinates from the next release, due to an SDNA limitation. Removed DispListMesh: This now fully replaced by DerivedMesh. To provide access to arrays of vertices, edges and faces, like DispListMesh does. The semantics of the DerivedMesh.getVertArray() and similar functions were changed to return a pointer to an array if one exists, or otherwise allocate a temporary one. On releasing the DerivedMesh, this temporary array will be removed automatically. Removed ssDM and meshDM DerivedMesh backends: The ssDM backend was for DispListMesh, so that became obsolete automatically. The meshDM backend was replaced by the custom data backend, that now figures out which layers need to be modified, and only duplicates those. This changes code in many places, and overall removes 2514 lines of code. So, there's a good chance this might break some stuff, although I've been testing it for a few days now. The good news is, adding multiple color and uv layers should now become easy.
2006-11-20 04:28:02 +00:00
"DNA_customdata_types.h",
"DNA_particle_types.h",
"DNA_cloth_types.h",
"DNA_gpencil_types.h",
2012-07-07 22:51:57 +00:00
/* if you add files here, please add them at the end
* of makesdna.c (this file) as well */
"DNA_windowmanager_types.h",
2.5: Blender "Animato" - New Animation System Finally, here is the basic (functional) prototype of the new animation system which will allow for the infamous "everything is animatable", and which also addresses several of the more serious shortcomings of the old system. Unfortunately, this will break old animation files (especially right now, as I haven't written the version patching code yet), however, this is for the future. Highlights of the new system: * Scrapped IPO-Curves/IPO/(Action+Constraint-Channels)/Action system, and replaced it with F-Curve/Action. - F-Curves (animators from other packages will feel at home with this name) replace IPO-Curves. - The 'new' Actions, act as the containers for F-Curves, so that they can be reused. They are therefore more akin to the old 'IPO' blocks, except they do not have the blocktype restriction, so you can store materials/texture/geometry F-Curves in the same Action as Object transforms, etc. * F-Curves use RNA-paths for Data Access, hence allowing "every" (where sensible/editable that is) user-accessible setting from RNA to be animated. * Drivers are no longer mixed with Animation Data, so rigs will not be that easily broken and several dependency problems can be eliminated. (NOTE: drivers haven't been hooked up yet, but the code is in place) * F-Curve modifier system allows useful 'large-scale' manipulation of F-Curve values, including (I've only included implemented ones here): envelope deform (similar to lattices to allow broad-scale reshaping of curves), curve generator (polynomial or py-expression), cycles (replacing the old cyclic extrapolation modes, giving more control over this). (NOTE: currently this cannot be tested, as there's not access to them, but the code is all in place) * NLA system with 'tracks' (i.e. layers), and multiple strips per track. (NOTE: NLA system is not yet functional, as it's only partially coded still) There are more nice things that I will be preparing some nice docs for soon, but for now, check for more details: http://lists.blender.org/pipermail/bf-taskforce25/2009-January/000260.html So, what currently works: * I've implemented two basic operators for the 3D-view only to Insert and Delete Keyframes. These are tempolary ones only that will be replaced in due course with 'proper' code. * Object Loc/Rot/Scale can be keyframed. Also, the colour of the 'active' material (Note: this should really be for nth material instead, but that doesn't work yet in RNA) can also be keyframed into the same datablock. * Standard animation refresh (i.e. animation resulting from NLA and Action evaluation) is now done completely separate from drivers before anything else is done after a frame change. Drivers are handled after this in a separate pass, as dictated by depsgraph flags, etc. Notes: * Drivers haven't been hooked up yet * Only objects and data directly linked to objects can be animated. * Depsgraph will need further tweaks. Currently, I've only made sure that it will update some things in the most basic cases (i.e. frame change). * Animation Editors are currently broken (in terms of editing stuff). This will be my next target (priority to get Dopesheet working first, then F-Curve editor - i.e. old IPO Editor) * I've had to put in large chunks of XXX sandboxing for old animation system code all around the place. This will be cleaned up in due course, as some places need special review. In particular, the particles and sequencer code have far too many manual calls to calculate + flush animation info, which is really bad (this is a 'please explain yourselves' call to Physics coders!).
2009-01-17 03:12:50 +00:00
"DNA_anim_types.h",
Initial code for boids v2 Too many new features to list! But here are the biggies: - Boids can move on air and/or land, or climb a goal object. - Proper interaction with collision objects. * Closest collision object in negative z direction is considered as ground. * Other collision objects are obstacles and boids collide with them. - Boid behavior rules are now added to a dynamic list. * Many new rules and many still not implemented. * Different rule evaluation modes (fuzzy, random, average). - Only particle systems defined by per system "boid relations" are considered for simulation of that system. * This is in addition to the boids own system of course. * Relations define other systems as "neutral", "friend" or "enemy". - All effectors now effect boid physics, not boid brains. * This allows forcing boids somewhere. * Exception to this is new "boid" effector, which defines boid predators (positive strength) and goals (negative strength). Known issue: - Boid health isn't yet stored in pointcache so simulations with "fight" rule are not be read from cache properly. - Object/Group visualization object's animation is not played in "particle time". This is definately the wanted behavior, but isn't possible with the current state of dupliobject code. Other new features: - Particle systems can now be named separately from particle settings. * Default name for particle settings is now "ParticleSettings" instead of "PSys" - Per particle system list of particle effector weights. * Enables different effection strengths for particles from different particle systems with without messing around with effector group setting. Other code changes: - KDTree now supports range search as it's needed for new boids. - "Keyed particle targets" renamed as general "particle targets", as they're needed for boids too. (this might break some files saved with new keyed particles) Bug fixes: - Object & group visualizations didn't work. - Interpolating pointcache didn't do rotation.
2009-07-20 23:52:53 +00:00
"DNA_boid_types.h",
"DNA_smoke_types.h",
"DNA_speaker_types.h",
Camera tracking integration =========================== Commiting camera tracking integration gsoc project into trunk. This commit includes: - Bundled version of libmv library (with some changes against official repo, re-sync with libmv repo a bit later) - New datatype ID called MovieClip which is optimized to work with movie clips (both of movie files and image sequences) and doing camera/motion tracking operations. - New editor called Clip Editor which is currently used for motion/tracking stuff only, but which can be easily extended to work with masks too. This editor supports: * Loading movie files/image sequences * Build proxies with different size for loaded movie clip, also supports building undistorted proxies to increase speed of playback in undistorted mode. * Manual lens distortion mode calibration using grid and grease pencil * Supervised 2D tracking using two different algorithms KLT and SAD. * Basic algorithm for feature detection * Camera motion solving. scene orientation - New constraints to "link" scene objects with solved motions from clip: * Follow Track (make object follow 2D motion of track with given name or parent object to reconstructed 3D position of track) * Camera Solver to make camera moving in the same way as reconstructed camera This commit NOT includes changes from tomato branch: - New nodes (they'll be commited as separated patch) - Automatic image offset guessing for image input node and image editor (need to do more tests and gather more feedback) - Code cleanup in libmv-capi. It's not so critical cleanup, just increasing readability and understanadability of code. Better to make this chaneg when Keir will finish his current patch. More details about this project can be found on this page: http://wiki.blender.org/index.php/User:Nazg-gul/GSoC-2011 Further development of small features would be done in trunk, bigger/experimental features would first be implemented in tomato branch.
2011-11-07 12:55:18 +00:00
"DNA_movieclip_types.h",
"DNA_tracking_types.h",
"DNA_dynamicpaint_types.h",
"DNA_mask_types.h",
2002-10-12 11:37:38 +00:00
2012-07-07 22:51:57 +00:00
/* empty string to indicate end of includefiles */
2002-10-12 11:37:38 +00:00
""
};
static int maxdata = 500000, maxnr = 50000;
static int nr_names = 0;
static int nr_types = 0;
static int nr_structs = 0;
static char **names, *namedata; /* at address names[a] is string a */
static char **types, *typedata; /* at address types[a] is string a */
static short *typelens_native; /* at typelens[a] is the length of type 'a' on this systems bitness (32 or 64) */
static short *typelens_64; /* contains sizes as they are calculated on 64 bit systems */
2012-05-27 19:40:36 +00:00
static short **structs, *structdata; /* at sp = structs[a] is the first address of a struct definition
* sp[0] is type number
* sp[1] is amount of elements
* sp[2] sp[3] is typenr, namenr (etc) */
/**
* Variable to control debug output of makesdna.
2002-10-12 11:37:38 +00:00
* debugSDNA:
* - 0 = no output, except errors
* - 1 = detail actions
* - 2 = full trace, tell which names and types were found
* - 4 = full trace, plus all gritty details
*/
static int debugSDNA = 0;
static int additional_slen_offset;
2002-10-12 11:37:38 +00:00
/* ************************************************************************** */
/* Functions */
/* ************************************************************************** */
/**
* Add type \c str to struct indexed by \c len, if it was not yet found.
* \param str char
* \param len int
2002-10-12 11:37:38 +00:00
*/
static int add_type(const char *str, int len);
2002-10-12 11:37:38 +00:00
/**
* Add variable \c str to
* \param str
2002-10-12 11:37:38 +00:00
*/
static int add_name(const char *str);
2002-10-12 11:37:38 +00:00
/**
* Search whether this structure type was already found, and if not,
* add it.
*/
static short *add_struct(int namecode);
2002-10-12 11:37:38 +00:00
/**
* Remove comments from this buffer. Assumes that the buffer refers to
* ascii-code text.
*/
static int preprocess_include(char *maindata, int len);
2002-10-12 11:37:38 +00:00
/**
* Scan this file for serializable types.
*/
static int convert_include(char *filename);
2002-10-12 11:37:38 +00:00
/**
* Determine how many bytes are needed for an array.
*/
static int arraysize(char *astr, int len);
2002-10-12 11:37:38 +00:00
/**
* Determine how many bytes are needed for each struct.
*/
static int calculate_structlens(int);
2002-10-12 11:37:38 +00:00
/**
* Construct the DNA.c file
*/
void dna_write(FILE *file, void *pntr, int size);
/**
* Report all structures found so far, and print their lengths.
2002-10-12 11:37:38 +00:00
*/
void printStructLengths(void);
2002-10-12 11:37:38 +00:00
/* ************************************************************************** */
/* Implementation */
/* ************************************************************************** */
/* ************************* MAKEN DNA ********************** */
static int add_type(const char *str, int len)
2002-10-12 11:37:38 +00:00
{
int nr;
char *cp;
/* first do validity check */
if (str[0] == 0) {
return -1;
}
else if (strchr(str, '*')) {
/* note: this is valid C syntax but we can't parse, complain!
* 'struct SomeStruct* somevar;' <-- correct but we cant handle right now. */
return -1;
}
2002-10-12 11:37:38 +00:00
/* search through type array */
for (nr = 0; nr < nr_types; nr++) {
if (strcmp(str, types[nr]) == 0) {
2002-10-12 11:37:38 +00:00
if (len) {
typelens_native[nr] = len;
typelens_64[nr] = len;
2002-10-12 11:37:38 +00:00
}
return nr;
}
}
/* append new type */
if (nr_types == 0) cp = typedata;
2002-10-12 11:37:38 +00:00
else {
cp = types[nr_types - 1] + strlen(types[nr_types - 1]) + 1;
2002-10-12 11:37:38 +00:00
}
strcpy(cp, str);
types[nr_types] = cp;
typelens_native[nr_types] = len;
typelens_64[nr_types] = len;
2002-10-12 11:37:38 +00:00
if (nr_types >= maxnr) {
2002-10-12 11:37:38 +00:00
printf("too many types\n");
return nr_types - 1;
2002-10-12 11:37:38 +00:00
}
nr_types++;
return nr_types - 1;
2002-10-12 11:37:38 +00:00
}
/**
*
* Because of the weird way of tokenizing, we have to 'cast' function
* pointers to ... (*f)(), whatever the original signature. In fact,
* we add name and type at the same time... There are two special
* cases, unfortunately. These are explicitly checked.
*
* */
static int add_name(const char *str)
2002-10-12 11:37:38 +00:00
{
int nr, i, j, k;
char *cp;
char buf[255]; /* stupid limit, change it :) */
const char *name;
2002-10-12 11:37:38 +00:00
additional_slen_offset = 0;
2012-05-25 09:51:53 +00:00
if (str[0] == 0 /* || (str[1] == 0) */) return -1;
2002-10-12 11:37:38 +00:00
if (str[0] == '(' && str[1] == '*') {
/* we handle function pointer and special array cases here, e.g.
2012-03-09 18:28:30 +00:00
* void (*function)(...) and float (*array)[..]. the array case
2012-07-29 00:20:28 +00:00
* name is still converted to (array *)() though because it is that
2012-03-09 18:28:30 +00:00
* way in old dna too, and works correct with elementsize() */
int isfuncptr = (strchr(str + 1, '(')) != NULL;
if (debugSDNA > 3) printf("\t\t\t\t*** Function pointer or multidim array pointer found\n");
2002-10-12 11:37:38 +00:00
/* functionpointer: transform the type (sometimes) */
i = 0;
while (str[i] != ')') {
buf[i] = str[i];
i++;
}
/* Another number we need is the extra slen offset. This extra
* offset is the overshoot after a space. If there is no
* space, no overshoot should be calculated. */
j = i; /* j at first closing brace */
if (debugSDNA > 3) printf("first brace after offset %d\n", i);
j++; /* j beyond closing brace ? */
while ((str[j] != 0) && (str[j] != ')')) {
if (debugSDNA > 3) printf("seen %c ( %d)\n", str[j], str[j]);
2002-10-12 11:37:38 +00:00
j++;
}
if (debugSDNA > 3) printf("seen %c ( %d)\n"
"special after offset%d\n",
str[j], str[j], j);
2002-10-12 11:37:38 +00:00
if (!isfuncptr) {
/* multidimensional array pointer case */
if (str[j] == 0) {
if (debugSDNA > 3) printf("offsetting for multidim array pointer\n");
}
else
printf("Error during tokening multidim array pointer\n");
}
else if (str[j] == 0) {
2002-10-12 11:37:38 +00:00
if (debugSDNA > 3) printf("offsetting for space\n");
/* get additional offset */
k = 0;
while (str[j] != ')') {
j++;
k++;
}
if (debugSDNA > 3) printf("extra offset %d\n", k);
additional_slen_offset = k;
}
else if (str[j] == ')') {
2002-10-12 11:37:38 +00:00
if (debugSDNA > 3) printf("offsetting for brace\n");
; /* don't get extra offset */
}
else {
2002-10-12 11:37:38 +00:00
printf("Error during tokening function pointer argument list\n");
}
/*
* Put )(void) at the end? Maybe )(). Should check this with
* old sdna. Actually, sometimes )(), sometimes )(void...)
* Alas.. such is the nature of braindamage :(
2002-10-12 11:37:38 +00:00
*
* Sorted it out: always do )(), except for headdraw and
* windraw, part of ScrArea. This is important, because some
* linkers will treat different fp's differently when called
* !!! This has to do with interference in byte-alignment and
* the way args are pushed on the stack.
*
* */
buf[i] = 0;
if (debugSDNA > 3) printf("Name before chomping: %s\n", buf);
2012-04-29 15:47:02 +00:00
if ((strncmp(buf, "(*headdraw", 10) == 0) ||
(strncmp(buf, "(*windraw", 9) == 0) )
{
2002-10-12 11:37:38 +00:00
buf[i] = ')';
buf[i + 1] = '(';
buf[i + 2] = 'v';
buf[i + 3] = 'o';
buf[i + 4] = 'i';
buf[i + 5] = 'd';
buf[i + 6] = ')';
buf[i + 7] = 0;
}
else {
2002-10-12 11:37:38 +00:00
buf[i] = ')';
buf[i + 1] = '(';
buf[i + 2] = ')';
buf[i + 3] = 0;
2002-10-12 11:37:38 +00:00
}
/* now precede with buf*/
if (debugSDNA > 3) printf("\t\t\t\t\tProposing fp name %s\n", buf);
2002-10-12 11:37:38 +00:00
name = buf;
}
else {
2002-10-12 11:37:38 +00:00
/* normal field: old code */
name = str;
}
/* search name array */
for (nr = 0; nr < nr_names; nr++) {
if (strcmp(name, names[nr]) == 0) {
2002-10-12 11:37:38 +00:00
return nr;
}
}
/* append new type */
if (nr_names == 0) cp = namedata;
2002-10-12 11:37:38 +00:00
else {
cp = names[nr_names - 1] + strlen(names[nr_names - 1]) + 1;
2002-10-12 11:37:38 +00:00
}
strcpy(cp, name);
names[nr_names] = cp;
2002-10-12 11:37:38 +00:00
if (nr_names >= maxnr) {
2002-10-12 11:37:38 +00:00
printf("too many names\n");
return nr_names - 1;
2002-10-12 11:37:38 +00:00
}
nr_names++;
return nr_names - 1;
2002-10-12 11:37:38 +00:00
}
static short *add_struct(int namecode)
2002-10-12 11:37:38 +00:00
{
int len;
short *sp;
if (nr_structs == 0) {
structs[0] = structdata;
2002-10-12 11:37:38 +00:00
}
else {
sp = structs[nr_structs - 1];
len = sp[1];
structs[nr_structs] = sp + 2 * len + 2;
2002-10-12 11:37:38 +00:00
}
sp = structs[nr_structs];
sp[0] = namecode;
2002-10-12 11:37:38 +00:00
if (nr_structs >= maxnr) {
2002-10-12 11:37:38 +00:00
printf("too many structs\n");
return sp;
}
nr_structs++;
return sp;
}
static int preprocess_include(char *maindata, int len)
2002-10-12 11:37:38 +00:00
{
int a, newlen, comment = 0;
char *cp, *temp, *md;
/* note: len + 1, last character is a dummy to prevent
* comparisons using uninitialized memory */
temp = MEM_mallocN(len + 1, "preprocess_include");
temp[len] = ' ';
2002-10-12 11:37:38 +00:00
memcpy(temp, maindata, len);
2012-07-07 22:51:57 +00:00
/* remove all c++ comments */
/* replace all enters/tabs/etc with spaces */
cp = temp;
a = len;
2002-10-12 11:37:38 +00:00
comment = 0;
while (a--) {
if (cp[0] == '/' && cp[1] == '/') {
2002-10-12 11:37:38 +00:00
comment = 1;
}
else if (*cp < 32) {
2002-10-12 11:37:38 +00:00
comment = 0;
}
if (comment || *cp < 32 || *cp > 128) *cp = 32;
2002-10-12 11:37:38 +00:00
cp++;
}
/* data from temp copy to maindata, remove comments and double spaces */
cp = temp;
md = maindata;
newlen = 0;
comment = 0;
a = len;
while (a--) {
2002-10-12 11:37:38 +00:00
if (cp[0] == '/' && cp[1] == '*') {
comment = 1;
cp[0] = cp[1] = 32;
2002-10-12 11:37:38 +00:00
}
if (cp[0] == '*' && cp[1] == '/') {
comment = 0;
cp[0] = cp[1] = 32;
2002-10-12 11:37:38 +00:00
}
/* do not copy when: */
2012-10-07 09:48:59 +00:00
if (comment) {
/* pass */
}
else if (cp[0] == ' ' && cp[1] == ' ') {
/* pass */
}
else if (cp[-1] == '*' && cp[0] == ' ') {
/* pointers with a space */
} /* skip special keywords */
else if (strncmp("DNA_DEPRECATED", cp, 14) == 0) {
/* single values are skipped already, so decrement 1 less */
a -= 13;
cp += 13;
}
2002-10-12 11:37:38 +00:00
else {
md[0] = cp[0];
2002-10-12 11:37:38 +00:00
md++;
newlen++;
}
cp++;
}
MEM_freeN(temp);
return newlen;
}
2005-03-14 20:10:22 +00:00
static void *read_file_data(char *filename, int *len_r)
2002-10-12 11:37:38 +00:00
{
#ifdef WIN32
FILE *fp = fopen(filename, "rb");
2002-10-12 11:37:38 +00:00
#else
FILE *fp = fopen(filename, "r");
2002-10-12 11:37:38 +00:00
#endif
void *data;
if (!fp) {
*len_r = -1;
2002-10-12 11:37:38 +00:00
return NULL;
}
fseek(fp, 0L, SEEK_END);
*len_r = ftell(fp);
2002-10-12 11:37:38 +00:00
fseek(fp, 0L, SEEK_SET);
data = MEM_mallocN(*len_r, "read_file_data");
2002-10-12 11:37:38 +00:00
if (!data) {
*len_r = -1;
fclose(fp);
2002-10-12 11:37:38 +00:00
return NULL;
}
if (fread(data, *len_r, 1, fp) != 1) {
*len_r = -1;
2002-10-12 11:37:38 +00:00
MEM_freeN(data);
fclose(fp);
2002-10-12 11:37:38 +00:00
return NULL;
}
fclose(fp);
2002-10-12 11:37:38 +00:00
return data;
}
static int convert_include(char *filename)
2002-10-12 11:37:38 +00:00
{
/* read include file, skip structs with a '#' before it.
2012-03-09 18:28:30 +00:00
* store all data in temporal arrays.
*/
2002-10-12 11:37:38 +00:00
int filelen, count, overslaan, slen, type, name, strct;
short *structpoin, *sp;
char *maindata, *mainend, *md, *md1;
md = maindata = read_file_data(filename, &filelen);
if (filelen == -1) {
2002-10-12 11:37:38 +00:00
printf("Can't read file %s\n", filename);
return 1;
}
filelen = preprocess_include(maindata, filelen);
mainend = maindata + filelen - 1;
2002-10-12 11:37:38 +00:00
/* we look for '{' and then back to 'struct' */
count = 0;
overslaan = 0;
while (count < filelen) {
2002-10-12 11:37:38 +00:00
/* code for skipping a struct: two hashes on 2 lines. (preprocess added a space) */
if (md[0] == '#' && md[1] == ' ' && md[2] == '#') {
overslaan = 1;
2002-10-12 11:37:38 +00:00
}
if (md[0] == '{') {
md[0] = 0;
if (overslaan) {
overslaan = 0;
2002-10-12 11:37:38 +00:00
}
else {
if (md[-1] == ' ') md[-1] = 0;
md1 = md - 2;
while (*md1 != 32) md1--; /* to beginning of word */
2002-10-12 11:37:38 +00:00
md1++;
/* we've got a struct name when... */
if (strncmp(md1 - 7, "struct", 6) == 0) {
2002-10-12 11:37:38 +00:00
strct = add_type(md1, 0);
if (strct == -1) {
printf("File '%s' contains struct we cant parse \"%s\"\n", filename, md1);
return 1;
}
structpoin = add_struct(strct);
sp = structpoin + 2;
2002-10-12 11:37:38 +00:00
if (debugSDNA > 1) printf("\t|\t|-- detected struct %s\n", types[strct]);
/* first lets make it all nice strings */
md1 = md + 1;
while (*md1 != '}') {
if (md1 > mainend) break;
2002-10-12 11:37:38 +00:00
if (*md1 == ',' || *md1 == ' ') *md1 = 0;
2002-10-12 11:37:38 +00:00
md1++;
}
/* read types and names until first character that is not '}' */
md1 = md + 1;
while (*md1 != '}') {
if (md1 > mainend) break;
2002-10-12 11:37:38 +00:00
/* skip when it says 'struct' or 'unsigned' or 'const' */
if (*md1) {
if (strncmp(md1, "struct", 6) == 0) md1 += 7;
if (strncmp(md1, "unsigned", 8) == 0) md1 += 9;
if (strncmp(md1, "const", 5) == 0) md1 += 6;
2002-10-12 11:37:38 +00:00
/* we've got a type! */
type = add_type(md1, 0);
if (type == -1) {
printf("File '%s' contains struct we can't parse \"%s\"\n", filename, md1);
return 1;
}
2002-10-12 11:37:38 +00:00
if (debugSDNA > 1) printf("\t|\t|\tfound type %s (", md1);
md1 += strlen(md1);
2002-10-12 11:37:38 +00:00
/* read until ';' */
while (*md1 != ';') {
if (md1 > mainend) break;
2002-10-12 11:37:38 +00:00
if (*md1) {
/* We've got a name. slen needs
2002-10-12 11:37:38 +00:00
* correction for function
* pointers! */
slen = (int) strlen(md1);
if (md1[slen - 1] == ';') {
md1[slen - 1] = 0;
2002-10-12 11:37:38 +00:00
name = add_name(md1);
2002-10-12 11:37:38 +00:00
slen += additional_slen_offset;
sp[0] = type;
sp[1] = name;
2002-10-12 11:37:38 +00:00
if ((debugSDNA > 1) && (names[name] != NULL)) printf("%s |", names[name]);
2002-10-12 11:37:38 +00:00
structpoin[1]++;
sp += 2;
2002-10-12 11:37:38 +00:00
md1 += slen;
2002-10-12 11:37:38 +00:00
break;
}
name = add_name(md1);
2002-10-12 11:37:38 +00:00
slen += additional_slen_offset;
sp[0] = type;
sp[1] = name;
if ((debugSDNA > 1) && (names[name] != NULL)) printf("%s ||", names[name]);
2002-10-12 11:37:38 +00:00
structpoin[1]++;
sp += 2;
2002-10-12 11:37:38 +00:00
md1 += slen;
2002-10-12 11:37:38 +00:00
}
md1++;
}
if (debugSDNA > 1) printf(")\n");
}
md1++;
}
}
}
}
count++;
md++;
}
MEM_freeN(maindata);
return 0;
}
static int arraysize(char *astr, int len)
2002-10-12 11:37:38 +00:00
{
int a, mul = 1;
char str[100], *cp = NULL;
2002-10-12 11:37:38 +00:00
memcpy(str, astr, len + 1);
2002-10-12 11:37:38 +00:00
for (a = 0; a < len; a++) {
if (str[a] == '[') {
cp = &(str[a + 1]);
2002-10-12 11:37:38 +00:00
}
else if (str[a] == ']' && cp) {
str[a] = 0;
/* if 'cp' is a preprocessor definition, it will evaluate to 0,
2012-05-16 23:37:23 +00:00
* the caller needs to check for this case and throw an error */
mul *= atoi(cp);
2002-10-12 11:37:38 +00:00
}
}
return mul;
}
static int calculate_structlens(int firststruct)
2002-10-12 11:37:38 +00:00
{
int a, b, len_native, len_64, unknown = nr_structs, lastunknown, structtype, type, mul, namelen;
2002-10-12 11:37:38 +00:00
short *sp, *structpoin;
char *cp;
int has_pointer, dna_error = 0;
while (unknown) {
lastunknown = unknown;
unknown = 0;
2002-10-12 11:37:38 +00:00
/* check all structs... */
for (a = 0; a < nr_structs; a++) {
structpoin = structs[a];
structtype = structpoin[0];
2002-10-12 11:37:38 +00:00
/* when length is not known... */
if (typelens_native[structtype] == 0) {
2002-10-12 11:37:38 +00:00
sp = structpoin + 2;
len_native = 0;
len_64 = 0;
2002-10-12 11:37:38 +00:00
has_pointer = 0;
/* check all elements in struct */
for (b = 0; b < structpoin[1]; b++, sp += 2) {
type = sp[0];
cp = names[sp[1]];
namelen = (int) strlen(cp);
/* is it a pointer or function pointer? */
if (cp[0] == '*' || cp[1] == '*') {
2002-10-12 11:37:38 +00:00
has_pointer = 1;
/* has the name an extra length? (array) */
mul = 1;
if (cp[namelen - 1] == ']') mul = arraysize(cp, namelen);
if (mul == 0) {
printf("Zero array size found or could not parse %s: '%.*s'\n", types[structtype], namelen + 1, cp);
dna_error = 1;
}
2002-10-12 11:37:38 +00:00
/* 4-8 aligned/ */
if (sizeof(void *) == 4) {
if (len_native % 4) {
printf("Align pointer error in struct (len_native 4): %s %s\n", types[structtype], cp);
2002-10-12 11:37:38 +00:00
dna_error = 1;
}
}
else {
if (len_native % 8) {
printf("Align pointer error in struct (len_native 8): %s %s\n", types[structtype], cp);
2002-10-12 11:37:38 +00:00
dna_error = 1;
}
}
if (len_64 % 8) {
printf("Align pointer error in struct (len_64 8): %s %s\n", types[structtype], cp);
2002-10-12 11:37:38 +00:00
dna_error = 1;
}
len_native += sizeof(void *) * mul;
len_64 += 8 * mul;
2002-10-12 11:37:38 +00:00
}
else if (cp[0] == '[') {
/* parsing can cause names "var" and "[3]" to be found for "float var [3]" ... */
printf("Parse error in struct, invalid member name: %s %s\n", types[structtype], cp);
dna_error = 1;
}
else if (typelens_native[type]) {
/* has the name an extra length? (array) */
mul = 1;
if (cp[namelen - 1] == ']') mul = arraysize(cp, namelen);
if (mul == 0) {
printf("Zero array size found or could not parse %s: '%.*s'\n", types[structtype], namelen + 1, cp);
dna_error = 1;
}
/* struct alignment */
if (type >= firststruct) {
if (sizeof(void *) == 8 && (len_native % 8) ) {
2012-04-29 15:47:02 +00:00
printf("Align struct error: %s %s\n", types[structtype], cp);
dna_error = 1;
}
}
/* 2-4-8 aligned/ */
if (type < firststruct && typelens_native[type] > 4 && (len_native % 8)) {
printf("Align 8 error in struct: %s %s (add %d padding bytes)\n", types[structtype], cp, len_native % 8);
dna_error = 1;
}
if (typelens_native[type] > 3 && (len_native % 4) ) {
printf("Align 4 error in struct: %s %s (add %d padding bytes)\n", types[structtype], cp, len_native % 4);
dna_error = 1;
2002-10-12 11:37:38 +00:00
}
else if (typelens_native[type] == 2 && (len_native % 2) ) {
printf("Align 2 error in struct: %s %s (add %d padding bytes)\n", types[structtype], cp, len_native % 2);
dna_error = 1;
2002-10-12 11:37:38 +00:00
}
len_native += mul * typelens_native[type];
len_64 += mul * typelens_64[type];
2002-10-12 11:37:38 +00:00
}
else {
len_native = 0;
len_64 = 0;
2002-10-12 11:37:38 +00:00
break;
}
}
if (len_native == 0) {
2002-10-12 11:37:38 +00:00
unknown++;
}
else {
typelens_native[structtype] = len_native;
typelens_64[structtype] = len_64;
2012-07-07 22:51:57 +00:00
/* two ways to detect if a struct contains a pointer:
* has_pointer is set or len_64 != len_native */
if (has_pointer || len_64 != len_native) {
if (len_64 % 8) {
printf("Sizeerror 8 in struct: %s (add %d bytes)\n", types[structtype], len_64 % 8);
2002-10-12 11:37:38 +00:00
dna_error = 1;
}
}
if (len_native % 4) {
printf("Sizeerror 4 in struct: %s (add %d bytes)\n", types[structtype], len_native % 4);
dna_error = 1;
}
2002-10-12 11:37:38 +00:00
}
}
}
if (unknown == lastunknown) break;
2002-10-12 11:37:38 +00:00
}
if (unknown) {
2002-10-12 11:37:38 +00:00
printf("ERROR: still %d structs unknown\n", unknown);
if (debugSDNA) {
printf("*** Known structs :\n");
2002-10-12 11:37:38 +00:00
for (a = 0; a < nr_structs; a++) {
structpoin = structs[a];
structtype = structpoin[0];
2002-10-12 11:37:38 +00:00
/* length unknown */
if (typelens_native[structtype] != 0) {
2002-10-12 11:37:38 +00:00
printf(" %s\n", types[structtype]);
}
}
}
printf("*** Unknown structs :\n");
2002-10-12 11:37:38 +00:00
for (a = 0; a < nr_structs; a++) {
structpoin = structs[a];
structtype = structpoin[0];
2002-10-12 11:37:38 +00:00
/* length unknown yet */
if (typelens_native[structtype] == 0) {
2002-10-12 11:37:38 +00:00
printf(" %s\n", types[structtype]);
}
}
dna_error = 1;
2002-10-12 11:37:38 +00:00
}
return(dna_error);
}
#define MAX_DNA_LINE_LENGTH 20
void dna_write(FILE *file, void *pntr, int size)
{
static int linelength = 0;
int i;
char *data;
data = (char *) pntr;
for (i = 0; i < size; i++) {
2012-04-29 15:47:02 +00:00
fprintf(file, "%d, ", data[i]);
2002-10-12 11:37:38 +00:00
linelength++;
if (linelength >= MAX_DNA_LINE_LENGTH) {
fprintf(file, "\n");
linelength = 0;
}
}
}
void printStructLengths(void)
2002-10-12 11:37:38 +00:00
{
int a, unknown = nr_structs, structtype;
/*int lastunknown;*/ /*UNUSED*/
2002-10-12 11:37:38 +00:00
short *structpoin;
printf("\n\n*** All detected structs:\n");
while (unknown) {
2012-05-27 19:40:36 +00:00
/*lastunknown = unknown;*/ /*UNUSED*/
unknown = 0;
2002-10-12 11:37:38 +00:00
/* check all structs... */
for (a = 0; a < nr_structs; a++) {
structpoin = structs[a];
structtype = structpoin[0];
printf("\t%s\t:%d\n", types[structtype], typelens_native[structtype]);
2002-10-12 11:37:38 +00:00
}
}
printf("*** End of list\n");
}
static int make_structDNA(char *baseDirectory, FILE *file)
2002-10-12 11:37:38 +00:00
{
int len, i;
short *sp;
/* str contains filenames. Since we now include paths, I stretched */
/* it a bit. Hope this is enough :) -nzc- */
char str[SDNA_MAX_FILENAME_LENGTH], *cp;
int firststruct;
if (debugSDNA > -1) {
fflush(stdout);
printf("Running makesdna at debug level %d\n", debugSDNA);
}
/* the longest known struct is 50k, so we assume 100k is sufficent! */
namedata = MEM_callocN(maxdata, "namedata");
typedata = MEM_callocN(maxdata, "typedata");
structdata = MEM_callocN(maxdata, "structdata");
2002-10-12 11:37:38 +00:00
/* a maximum of 5000 variables, must be sufficient? */
names = MEM_callocN(sizeof(char *) * maxnr, "names");
types = MEM_callocN(sizeof(char *) * maxnr, "types");
typelens_native = MEM_callocN(sizeof(short) * maxnr, "typelens_native");
typelens_64 = MEM_callocN(sizeof(short) * maxnr, "typelens_64");
structs = MEM_callocN(sizeof(short) * maxnr, "structs");
2002-10-12 11:37:38 +00:00
/* insertion of all known types */
/* watch it: uint is not allowed! use in structs an unsigned int */
/* watch it: sizes must match DNA_elem_type_size() */
add_type("char", 1); /* SDNA_TYPE_CHAR */
add_type("uchar", 1); /* SDNA_TYPE_UCHAR */
add_type("short", 2); /* SDNA_TYPE_SHORT */
add_type("ushort", 2); /* SDNA_TYPE_USHORT */
add_type("int", 4); /* SDNA_TYPE_INT */
add_type("long", 4); /* SDNA_TYPE_LONG */ /* should it be 8 on 64 bits? */
add_type("ulong", 4); /* SDNA_TYPE_ULONG */
add_type("float", 4); /* SDNA_TYPE_FLOAT */
add_type("double", 8); /* SDNA_TYPE_DOUBLE */
add_type("int64_t", 8); /* SDNA_TYPE_INT64 */
add_type("uint64_t", 8); /* SDNA_TYPE_UINT64 */
add_type("void", 0); /* SDNA_TYPE_VOID */
2002-10-12 11:37:38 +00:00
2012-07-07 22:51:57 +00:00
/* the defines above shouldn't be output in the padding file... */
2002-10-12 11:37:38 +00:00
firststruct = nr_types;
/* add all include files defined in the global array */
/* Since the internal file+path name buffer has limited length, I do a */
/* little test first... */
/* Mind the breaking condition here! */
if (debugSDNA) printf("\tStart of header scan:\n");
for (i = 0; strlen(includefiles[i]); i++) {
sprintf(str, "%s%s", baseDirectory, includefiles[i]);
if (debugSDNA) printf("\t|-- Converting %s\n", str);
if (convert_include(str)) {
return (1);
2002-10-12 11:37:38 +00:00
}
}
if (debugSDNA) printf("\tFinished scanning %d headers.\n", i);
if (calculate_structlens(firststruct)) {
2012-07-07 22:51:57 +00:00
/* error */
2002-10-12 11:37:38 +00:00
return(1);
}
/* FOR DEBUG */
if (debugSDNA > 1) {
2012-04-29 15:47:02 +00:00
int a, b;
/* short *elem; */
2002-10-12 11:37:38 +00:00
short num_types;
printf("nr_names %d nr_types %d nr_structs %d\n", nr_names, nr_types, nr_structs);
for (a = 0; a < nr_names; a++) {
printf(" %s\n", names[a]);
2002-10-12 11:37:38 +00:00
}
printf("\n");
sp = typelens_native;
for (a = 0; a < nr_types; a++, sp++) {
2002-10-12 11:37:38 +00:00
printf(" %s %d\n", types[a], *sp);
}
printf("\n");
for (a = 0; a < nr_structs; a++) {
sp = structs[a];
printf(" struct %s elems: %d size: %d\n", types[sp[0]], sp[1], typelens_native[sp[0]]);
2002-10-12 11:37:38 +00:00
num_types = sp[1];
sp += 2;
2002-10-12 11:37:38 +00:00
/* ? num_types was elem? */
for (b = 0; b < num_types; b++, sp += 2) {
2002-10-12 11:37:38 +00:00
printf(" %s %s\n", types[sp[0]], names[sp[1]]);
}
}
}
/* file writing */
2002-10-12 11:37:38 +00:00
if (debugSDNA > -1) printf("Writing file ... ");
2012-10-07 09:48:59 +00:00
if (nr_names == 0 || nr_structs == 0) {
/* pass */
}
2002-10-12 11:37:38 +00:00
else {
strcpy(str, "SDNA");
dna_write(file, str, 4);
/* write names */
2002-10-12 11:37:38 +00:00
strcpy(str, "NAME");
dna_write(file, str, 4);
len = nr_names;
2002-10-12 11:37:38 +00:00
dna_write(file, &len, 4);
/* calculate size of datablock with strings */
cp = names[nr_names - 1];
cp += strlen(names[nr_names - 1]) + 1; /* +1: null-terminator */
len = (intptr_t) (cp - (char *) names[0]);
len = (len + 3) & ~3;
2002-10-12 11:37:38 +00:00
dna_write(file, names[0], len);
/* write TYPES */
2002-10-12 11:37:38 +00:00
strcpy(str, "TYPE");
dna_write(file, str, 4);
len = nr_types;
2002-10-12 11:37:38 +00:00
dna_write(file, &len, 4);
/* calculate datablock size */
cp = types[nr_types - 1];
cp += strlen(types[nr_types - 1]) + 1; /* +1: null-terminator */
len = (intptr_t) (cp - (char *) types[0]);
len = (len + 3) & ~3;
2002-10-12 11:37:38 +00:00
dna_write(file, types[0], len);
/* WRITE TYPELENGTHS */
2002-10-12 11:37:38 +00:00
strcpy(str, "TLEN");
dna_write(file, str, 4);
len = 2 * nr_types;
if (nr_types & 1) len += 2;
dna_write(file, typelens_native, len);
2002-10-12 11:37:38 +00:00
/* WRITE STRUCTS */
2002-10-12 11:37:38 +00:00
strcpy(str, "STRC");
dna_write(file, str, 4);
len = nr_structs;
2002-10-12 11:37:38 +00:00
dna_write(file, &len, 4);
/* calc datablock size */
sp = structs[nr_structs - 1];
sp += 2 + 2 * (sp[1]);
len = (intptr_t) ((char *) sp - (char *) structs[0]);
len = (len + 3) & ~3;
2002-10-12 11:37:38 +00:00
dna_write(file, structs[0], len);
/* a simple dna padding test */
2002-10-12 11:37:38 +00:00
if (0) {
FILE *fp;
int a;
fp = fopen("padding.c", "w");
2012-10-14 13:08:19 +00:00
if (fp == NULL) {
/* pass */
}
2002-10-12 11:37:38 +00:00
else {
2012-07-07 22:51:57 +00:00
/* add all include files defined in the global array */
2002-10-12 11:37:38 +00:00
for (i = 0; strlen(includefiles[i]); i++) {
fprintf(fp, "#include \"%s%s\"\n", baseDirectory, includefiles[i]);
2002-10-12 11:37:38 +00:00
}
fprintf(fp, "main() {\n");
sp = typelens_native;
2002-10-12 11:37:38 +00:00
sp += firststruct;
for (a = firststruct; a < nr_types; a++, sp++) {
if (*sp) {
2012-04-21 12:51:47 +00:00
fprintf(fp, "\tif (sizeof(struct %s) - %d) printf(\"ALIGN ERROR:", types[a], *sp);
fprintf(fp, "%%d %s %d ", types[a], *sp);
fprintf(fp, "\\n\", sizeof(struct %s) - %d);\n", types[a], *sp);
}
2002-10-12 11:37:38 +00:00
}
fprintf(fp, "}\n");
fclose(fp);
}
}
/* end end padding test */
}
MEM_freeN(namedata);
MEM_freeN(typedata);
MEM_freeN(structdata);
MEM_freeN(names);
MEM_freeN(types);
MEM_freeN(typelens_native);
MEM_freeN(typelens_64);
2002-10-12 11:37:38 +00:00
MEM_freeN(structs);
if (debugSDNA > -1) printf("done.\n");
return(0);
}
/* ************************* END MAKE DNA ********************** */
2002-10-12 11:37:38 +00:00
static void make_bad_file(const char *file, int line)
2002-10-12 11:37:38 +00:00
{
FILE *fp = fopen(file, "w");
fprintf(fp, "#error \"Error! can't make correct DNA.c file from %s:%d, STUPID!\"\n", __FILE__, line);
2002-10-12 11:37:38 +00:00
fclose(fp);
}
#ifndef BASE_HEADER
#define BASE_HEADER "../"
#endif
int main(int argc, char **argv)
2002-10-12 11:37:38 +00:00
{
FILE *file;
int return_status = 0;
if (argc != 2 && argc != 3) {
printf("Usage: %s outfile.c [base directory]\n", argv[0]);
2002-10-12 11:37:38 +00:00
return_status = 1;
}
else {
2002-10-12 11:37:38 +00:00
file = fopen(argv[1], "w");
if (!file) {
printf("Unable to open file: %s\n", argv[1]);
2002-10-12 11:37:38 +00:00
return_status = 1;
}
else {
char baseDirectory[256];
if (argc == 3) {
strcpy(baseDirectory, argv[2]);
}
else {
strcpy(baseDirectory, BASE_HEADER);
}
2012-10-22 08:15:51 +00:00
fprintf(file, "const unsigned char DNAstr[] = {\n");
if (make_structDNA(baseDirectory, file)) {
2012-07-07 22:51:57 +00:00
/* error */
2002-10-12 11:37:38 +00:00
fclose(file);
make_bad_file(argv[1], __LINE__);
2002-10-12 11:37:38 +00:00
return_status = 1;
}
else {
2002-10-12 11:37:38 +00:00
fprintf(file, "};\n");
2012-10-22 08:15:51 +00:00
fprintf(file, "const int DNAlen = sizeof(DNAstr);\n");
2002-10-12 11:37:38 +00:00
fclose(file);
}
}
}
return(return_status);
}
/* handy but fails on struct bounds which makesdna doesnt care about
* with quite the same strictness as GCC does */
#if 0
/* include files for automatic dependencies */
/* extra safety check that we are aligned,
* warnings here are easier to fix the makesdna's */
#ifdef __GNUC__
# pragma GCC diagnostic error "-Wpadded"
#endif
#endif /* if 0 */
2002-10-12 11:37:38 +00:00
#include "DNA_listBase.h"
#include "DNA_vec_types.h"
#include "DNA_ID.h"
#include "DNA_ipo_types.h"
#include "DNA_key_types.h"
#include "DNA_text_types.h"
#include "DNA_packedFile_types.h"
#include "DNA_camera_types.h"
#include "DNA_image_types.h"
#include "DNA_texture_types.h"
#include "DNA_lamp_types.h"
#include "DNA_material_types.h"
#include "DNA_vfont_types.h"
#include "DNA_meta_types.h"
#include "DNA_curve_types.h"
#include "DNA_mesh_types.h"
#include "DNA_meshdata_types.h"
#include "DNA_modifier_types.h"
2002-10-12 11:37:38 +00:00
#include "DNA_lattice_types.h"
#include "DNA_object_types.h"
#include "DNA_object_force.h"
#include "DNA_object_fluidsim.h"
2002-10-12 11:37:38 +00:00
#include "DNA_world_types.h"
#include "DNA_scene_types.h"
#include "DNA_view3d_types.h"
#include "DNA_view2d_types.h"
#include "DNA_space_types.h"
#include "DNA_userdef_types.h"
#include "DNA_screen_types.h"
#include "DNA_sdna_types.h"
#include "DNA_fileglobal_types.h"
#include "DNA_sequence_types.h"
#include "DNA_effect_types.h"
#include "DNA_outliner_types.h"
2002-10-12 11:37:38 +00:00
#include "DNA_property_types.h"
#include "DNA_sensor_types.h"
#include "DNA_controller_types.h"
#include "DNA_actuator_types.h"
#include "DNA_sound_types.h"
#include "DNA_group_types.h"
#include "DNA_armature_types.h"
#include "DNA_action_types.h"
#include "DNA_constraint_types.h"
#include "DNA_nla_types.h"
#include "DNA_node_types.h"
Orange: - New UI element: the "Curve Button". For mapping ranges (like 0 - 1) to another range, the curve button can be used for proportional falloff, bone influences, painting density, etc. Most evident use is of course to map RGB color with curves. To be able to use it, you have to allocate a CurveMapping struct and pass this on to the button. The CurveMapping API is in the new C file blenkernel/intern/colortools.c It's as simple as calling: curvemap= curvemapping_add(3, 0, 0, 1, 1) Which will create 3 curves, and sets a default 0-1 range. The current code only supports up to 4 curves maximum per mapping struct. The CurveMap button in Blender than handles allmost all editing. Evaluating a single channel: float newvalue= curvemapping_evaluateF(curvemap, 0, oldval); Where the second argument is the channel index, here 0-1-2 are possible. Or mapping a vector: curvemapping_evaluate3F(curvemap, newvec, oldvec); Optimized versions for byte or short mapping is possible too, not done yet. In butspace.c I've added a template wrapper for buttons around the curve, to reveil settings or show tools; check this screenie: http://www.blender.org/bf/curves.jpg - Buttons R, G, B: select channel - icons + and -: zoom in, out - icon 'wrench': menu with tools, like clear curve, set handle type - icon 'clipping': menu with clip values, and to dis/enable clipping - icon 'x': delete selection In the curve button itself, only LMB clicks are handled (like all UI elements in Blender). - click on point: select - shift+click on point: swap select - click on point + drag: select point (if not selected) and move it - click outside point + drag: translate view - CTRL+click: add new point - hold SHIFT while dragging to snap to grid (Yes I know... either one of these can be Blender compliant, not both!) - if you drag a point exactly on top of another, it merges them Other fixes: - Icons now draw using "Safe RasterPos", so they align with pixel boundary. the old code made ints from the raster pos coordinate, which doesn't work well for zoom in/out situations - bug in Node editing: buttons could not get freed, causing in memory error prints at end of a Blender session. That one was a very simple, but nasty error causing me all evening last night to find! (Hint; check diff of editnode.c, where uiDoButtons is called) Last note: this adds 3 new files in our tree, I did scons, but not MSVC!
2006-01-08 11:41:06 +00:00
#include "DNA_color_types.h"
#include "DNA_brush_types.h"
Added custom vertex/edge/face data for meshes: All data layers, including MVert/MEdge/MFace, are now managed as custom data layers. The pointers like Mesh.mvert, Mesh.dvert or Mesh.mcol are still used of course, but allocating, copying or freeing these arrays should be done through the CustomData API. Work in progress documentation on this is here: http://mediawiki.blender.org/index.php/BlenderDev/BlenderArchitecture/CustomData Replaced TFace by MTFace: This is the same struct, except that it does not contain color, that now always stays separated in MCol. This was not a good design decision to begin with, and it is needed for adding multiple color layers later. Note that this does mean older Blender versions will not be able to read UV coordinates from the next release, due to an SDNA limitation. Removed DispListMesh: This now fully replaced by DerivedMesh. To provide access to arrays of vertices, edges and faces, like DispListMesh does. The semantics of the DerivedMesh.getVertArray() and similar functions were changed to return a pointer to an array if one exists, or otherwise allocate a temporary one. On releasing the DerivedMesh, this temporary array will be removed automatically. Removed ssDM and meshDM DerivedMesh backends: The ssDM backend was for DispListMesh, so that became obsolete automatically. The meshDM backend was replaced by the custom data backend, that now figures out which layers need to be modified, and only duplicates those. This changes code in many places, and overall removes 2514 lines of code. So, there's a good chance this might break some stuff, although I've been testing it for a few days now. The good news is, adding multiple color and uv layers should now become easy.
2006-11-20 04:28:02 +00:00
#include "DNA_customdata_types.h"
#include "DNA_particle_types.h"
#include "DNA_cloth_types.h"
#include "DNA_gpencil_types.h"
#include "DNA_windowmanager_types.h"
2.5: Blender "Animato" - New Animation System Finally, here is the basic (functional) prototype of the new animation system which will allow for the infamous "everything is animatable", and which also addresses several of the more serious shortcomings of the old system. Unfortunately, this will break old animation files (especially right now, as I haven't written the version patching code yet), however, this is for the future. Highlights of the new system: * Scrapped IPO-Curves/IPO/(Action+Constraint-Channels)/Action system, and replaced it with F-Curve/Action. - F-Curves (animators from other packages will feel at home with this name) replace IPO-Curves. - The 'new' Actions, act as the containers for F-Curves, so that they can be reused. They are therefore more akin to the old 'IPO' blocks, except they do not have the blocktype restriction, so you can store materials/texture/geometry F-Curves in the same Action as Object transforms, etc. * F-Curves use RNA-paths for Data Access, hence allowing "every" (where sensible/editable that is) user-accessible setting from RNA to be animated. * Drivers are no longer mixed with Animation Data, so rigs will not be that easily broken and several dependency problems can be eliminated. (NOTE: drivers haven't been hooked up yet, but the code is in place) * F-Curve modifier system allows useful 'large-scale' manipulation of F-Curve values, including (I've only included implemented ones here): envelope deform (similar to lattices to allow broad-scale reshaping of curves), curve generator (polynomial or py-expression), cycles (replacing the old cyclic extrapolation modes, giving more control over this). (NOTE: currently this cannot be tested, as there's not access to them, but the code is all in place) * NLA system with 'tracks' (i.e. layers), and multiple strips per track. (NOTE: NLA system is not yet functional, as it's only partially coded still) There are more nice things that I will be preparing some nice docs for soon, but for now, check for more details: http://lists.blender.org/pipermail/bf-taskforce25/2009-January/000260.html So, what currently works: * I've implemented two basic operators for the 3D-view only to Insert and Delete Keyframes. These are tempolary ones only that will be replaced in due course with 'proper' code. * Object Loc/Rot/Scale can be keyframed. Also, the colour of the 'active' material (Note: this should really be for nth material instead, but that doesn't work yet in RNA) can also be keyframed into the same datablock. * Standard animation refresh (i.e. animation resulting from NLA and Action evaluation) is now done completely separate from drivers before anything else is done after a frame change. Drivers are handled after this in a separate pass, as dictated by depsgraph flags, etc. Notes: * Drivers haven't been hooked up yet * Only objects and data directly linked to objects can be animated. * Depsgraph will need further tweaks. Currently, I've only made sure that it will update some things in the most basic cases (i.e. frame change). * Animation Editors are currently broken (in terms of editing stuff). This will be my next target (priority to get Dopesheet working first, then F-Curve editor - i.e. old IPO Editor) * I've had to put in large chunks of XXX sandboxing for old animation system code all around the place. This will be cleaned up in due course, as some places need special review. In particular, the particles and sequencer code have far too many manual calls to calculate + flush animation info, which is really bad (this is a 'please explain yourselves' call to Physics coders!).
2009-01-17 03:12:50 +00:00
#include "DNA_anim_types.h"
Initial code for boids v2 Too many new features to list! But here are the biggies: - Boids can move on air and/or land, or climb a goal object. - Proper interaction with collision objects. * Closest collision object in negative z direction is considered as ground. * Other collision objects are obstacles and boids collide with them. - Boid behavior rules are now added to a dynamic list. * Many new rules and many still not implemented. * Different rule evaluation modes (fuzzy, random, average). - Only particle systems defined by per system "boid relations" are considered for simulation of that system. * This is in addition to the boids own system of course. * Relations define other systems as "neutral", "friend" or "enemy". - All effectors now effect boid physics, not boid brains. * This allows forcing boids somewhere. * Exception to this is new "boid" effector, which defines boid predators (positive strength) and goals (negative strength). Known issue: - Boid health isn't yet stored in pointcache so simulations with "fight" rule are not be read from cache properly. - Object/Group visualization object's animation is not played in "particle time". This is definately the wanted behavior, but isn't possible with the current state of dupliobject code. Other new features: - Particle systems can now be named separately from particle settings. * Default name for particle settings is now "ParticleSettings" instead of "PSys" - Per particle system list of particle effector weights. * Enables different effection strengths for particles from different particle systems with without messing around with effector group setting. Other code changes: - KDTree now supports range search as it's needed for new boids. - "Keyed particle targets" renamed as general "particle targets", as they're needed for boids too. (this might break some files saved with new keyed particles) Bug fixes: - Object & group visualizations didn't work. - Interpolating pointcache didn't do rotation.
2009-07-20 23:52:53 +00:00
#include "DNA_boid_types.h"
#include "DNA_smoke_types.h"
#include "DNA_speaker_types.h"
Camera tracking integration =========================== Commiting camera tracking integration gsoc project into trunk. This commit includes: - Bundled version of libmv library (with some changes against official repo, re-sync with libmv repo a bit later) - New datatype ID called MovieClip which is optimized to work with movie clips (both of movie files and image sequences) and doing camera/motion tracking operations. - New editor called Clip Editor which is currently used for motion/tracking stuff only, but which can be easily extended to work with masks too. This editor supports: * Loading movie files/image sequences * Build proxies with different size for loaded movie clip, also supports building undistorted proxies to increase speed of playback in undistorted mode. * Manual lens distortion mode calibration using grid and grease pencil * Supervised 2D tracking using two different algorithms KLT and SAD. * Basic algorithm for feature detection * Camera motion solving. scene orientation - New constraints to "link" scene objects with solved motions from clip: * Follow Track (make object follow 2D motion of track with given name or parent object to reconstructed 3D position of track) * Camera Solver to make camera moving in the same way as reconstructed camera This commit NOT includes changes from tomato branch: - New nodes (they'll be commited as separated patch) - Automatic image offset guessing for image input node and image editor (need to do more tests and gather more feedback) - Code cleanup in libmv-capi. It's not so critical cleanup, just increasing readability and understanadability of code. Better to make this chaneg when Keir will finish his current patch. More details about this project can be found on this page: http://wiki.blender.org/index.php/User:Nazg-gul/GSoC-2011 Further development of small features would be done in trunk, bigger/experimental features would first be implemented in tomato branch.
2011-11-07 12:55:18 +00:00
#include "DNA_movieclip_types.h"
#include "DNA_tracking_types.h"
#include "DNA_dynamicpaint_types.h"
#include "DNA_mask_types.h"
2002-10-12 11:37:38 +00:00
/* end of list */