Skip to content

Commit

Permalink
UPBGE: Setup conversion system from older/non UPBGE file version.
Browse files Browse the repository at this point in the history
Previously there was no difference between a UPBGE file version and a regular one, it cause some double conversion on file
that doesn't requierd it.
The UPBGE version is now treated as an independant file version system, to do this upbge[sub]version[file] was added in
Main struct and FileGlobal struct. The new conversion function is named blo_do_versions_upbge contained in versioning_upbge.c.
This function do all kind of conversion to UPBGE file. If the file was written with regular blender, the version and subversion
will be to 0, else it will be like 0 and 3 for the moment.
Two macro was added for the UPBGE version/subversion : UPBGE_[SUB]VERSION to 0 and 3.
  • Loading branch information
panzergame committed Jan 25, 2016
1 parent e9b13c0 commit 3b0413a
Show file tree
Hide file tree
Showing 9 changed files with 84 additions and 13 deletions.
3 changes: 3 additions & 0 deletions source/blender/blenkernel/BKE_blender.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ extern "C" {
#define BLENDER_MINVERSION 270
#define BLENDER_MINSUBVERSION 6

#define UPBGE_VERSION 0
#define UPBGE_SUBVERSION 3

/* used by packaging tools */
/* can be left blank, otherwise a,b,c... etc with no quotes */
#define BLENDER_VERSION_CHAR
Expand Down
4 changes: 4 additions & 0 deletions source/blender/blenkernel/BKE_main.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ typedef struct Main {
struct Main *next, *prev;
char name[1024]; /* 1024 = FILE_MAX */
short versionfile, subversionfile; /* see BLENDER_VERSION, BLENDER_SUBVERSION */
short upbgeversionfile, upbgesubversionfile;
short minversionfile, minsubversionfile;
uint64_t build_commit_timestamp; /* commit's timestamp from buildinfo */
char build_hash[16]; /* hash from buildinfo */
Expand Down Expand Up @@ -114,6 +115,9 @@ typedef struct Main {
#define MAIN_VERSION_ATLEAST(main, ver, subver) \
((main)->versionfile > (ver) || (main->versionfile == (ver) && (main)->subversionfile >= (subver)))

#define MAIN_VERSION_UPBGE_ATLEAST(main, ver, subver) \
((main)->upbgeversionfile > (ver) || (main->upbgeversionfile == (ver) && (main)->upbgesubversionfile >= (subver)))

#define MAIN_VERSION_OLDER(main, ver, subver) \
((main)->versionfile < (ver) || (main->versionfile == (ver) && (main)->subversionfile < (subver)))

Expand Down
1 change: 1 addition & 0 deletions source/blender/blenloader/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ set(SRC
intern/versioning_250.c
intern/versioning_260.c
intern/versioning_270.c
intern/versioning_upbge.c
intern/versioning_defaults.c
intern/versioning_legacy.c
intern/writefile.c
Expand Down
3 changes: 3 additions & 0 deletions source/blender/blenloader/intern/readfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -8077,6 +8077,8 @@ static BHead *read_global(BlendFileData *bfd, FileData *fd, BHead *bhead)

/* copy to bfd handle */
bfd->main->subversionfile = fg->subversion;
bfd->main->upbgeversionfile = fg->upbgeversion;
bfd->main->upbgesubversionfile = fg->upbgesubversion;
bfd->main->minversionfile = fg->minversion;
bfd->main->minsubversionfile = fg->minsubversion;
bfd->main->build_commit_timestamp = fg->build_commit_timestamp;
Expand Down Expand Up @@ -8195,6 +8197,7 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
blo_do_versions_250(fd, lib, main);
blo_do_versions_260(fd, lib, main);
blo_do_versions_270(fd, lib, main);
blo_do_versions_upbge(fd, lib, main);

/* WATCH IT!!!: pointers from libdata have not been converted yet here! */
/* WATCH IT 2!: Userdef struct init see do_versions_userdef() above! */
Expand Down
1 change: 1 addition & 0 deletions source/blender/blenloader/intern/readfile.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ void blo_do_versions_pre250(struct FileData *fd, struct Library *lib, struct Mai
void blo_do_versions_250(struct FileData *fd, struct Library *lib, struct Main *main);
void blo_do_versions_260(struct FileData *fd, struct Library *lib, struct Main *main);
void blo_do_versions_270(struct FileData *fd, struct Library *lib, struct Main *main);
void blo_do_versions_upbge(struct FileData *fd, struct Library *lib, struct Main *main);

#endif

12 changes: 0 additions & 12 deletions source/blender/blenloader/intern/versioning_270.c
Original file line number Diff line number Diff line change
Expand Up @@ -1044,18 +1044,6 @@ void blo_do_versions_270(FileData *fd, Library *UNUSED(lib), Main *main)
ob->max_jumps = 1;
}
}
if (!DNA_struct_elem_find(fd->filesdna, "bRaySensor", "int", "mask")) {
bRaySensor *raySensor;

for (Object *ob = main->object.first; ob; ob = ob->id.next) {
for(bSensor* sensor = ob->sensors.first; sensor != NULL; sensor = (bSensor *)sensor->next) {
if(sensor->type == SENS_RAY) {
raySensor = (bRaySensor *)sensor->data;
raySensor->mask = 0xFFFF;//all one, 'cause this was the previous behavior
}
}
}
}
}
if (!MAIN_VERSION_ATLEAST(main, 276, 5)) {
ListBase *lbarray[MAX_LIBARRAY];
Expand Down
67 changes: 67 additions & 0 deletions source/blender/blenloader/intern/versioning_upbge.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* ***** BEGIN GPL LICENSE BLOCK *****
*
* 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.
*
* 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,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Contributor(s): Blender Foundation
*
* ***** END GPL LICENSE BLOCK *****
*
*/

/** \file blender/blenloader/intern/versioning_upbge.c
* \ingroup blenloader
*/

#include "BLI_utildefines.h"
#include "BLI_compiler_attrs.h"

#include <stdio.h>

/* allow readfile to use deprecated functionality */
#define DNA_DEPRECATED_ALLOW

#include "DNA_genfile.h"
#include "DNA_object_types.h"
#include "DNA_sdna_types.h"
#include "DNA_sensor_types.h"
#include "DNA_space_types.h"

#include "BKE_main.h"

#include "BLO_readfile.h"

#include "readfile.h"

#include "MEM_guardedalloc.h"

void blo_do_versions_upbge(FileData *fd, Library *UNUSED(lib), Main *main)
{
//printf("UPBGE: open file from version : %i, subversion : %i\n", main->upbgeversionfile, main->upbgesubversionfile);
if (!MAIN_VERSION_UPBGE_ATLEAST(main, 0, 1)) {
if (!DNA_struct_elem_find(fd->filesdna, "bRaySensor", "int", "mask")) {
bRaySensor *raySensor;

for (Object *ob = main->object.first; ob; ob = ob->id.next) {
for(bSensor* sensor = ob->sensors.first; sensor != NULL; sensor = (bSensor *)sensor->next) {
if(sensor->type == SENS_RAY) {
raySensor = (bRaySensor *)sensor->data;
raySensor->mask = 0xFFFF;//all one, 'cause this was the previous behavior
}
}
}
}
}
}
2 changes: 2 additions & 0 deletions source/blender/blenloader/intern/writefile.c
Original file line number Diff line number Diff line change
Expand Up @@ -3660,6 +3660,8 @@ static void write_global(WriteData *wd, int fileflags, Main *mainvar)
memcpy(fg.subvstr, subvstr, 4);

fg.subversion= BLENDER_SUBVERSION;
fg.upbgeversion = UPBGE_VERSION;
fg.upbgesubversion = UPBGE_SUBVERSION;
fg.minversion= BLENDER_MINVERSION;
fg.minsubversion= BLENDER_MINSUBVERSION;
#ifdef WITH_BUILDINFO
Expand Down
4 changes: 3 additions & 1 deletion source/blender/makesdna/DNA_fileglobal_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,10 @@ struct Scene;
typedef struct FileGlobal {
char subvstr[4]; /* needs to be here, for human fileformat recognition */
short subversion;
short upbgeversion;
short upbgesubversion;
short minversion, minsubversion;
char pad[6];
char pad[2];
struct bScreen *curscreen;
struct Scene *curscene;
int fileflags;
Expand Down

0 comments on commit 3b0413a

Please sign in to comment.