More Build tools improvements:

- JFBuild ports: arttool, givedepth, and mkpalette
 - All viable tools are now built when 'make utils' is invoked, not just some
 - Revert "initprintf" hack of previous commit and replace it with "compat_tools.c"
 - Move Bstrtolower from baselayer.c to compat.c
 - Makefiles: Add start and finish messages for the tools
 - Makefiles: To prevent "-Wimplicit" from being passed to the C++ compiler, create $(*CONLYFLAGS)

git-svn-id: https://svn.eduke32.com/eduke32@2458 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
hendricks266 2012-03-12 04:48:42 +00:00
parent d0e0738f4f
commit c5519e3fe8
17 changed files with 1416 additions and 61 deletions

View file

@ -39,6 +39,7 @@ OURCFLAGS=$(BASECFLAGS) \
-I$(INC) -I$(EINC) -I$(SRC)/jmact -I$(JAUDIOLIBDIR)/include -I$(ENETDIR)/include
OURCXXFLAGS=$(BASECXXFLAGS)
OURCONLYFLAGS=$(BASECONLYFLAGS)
NASMFLAGS=$(BASEASFLAGS)
MISCLINKOPTS=
@ -250,7 +251,6 @@ endif
OURCFLAGS+= $(BUILDCFLAGS)
OURCXXFLAGS+= $(BUILDCFLAGS)
ifeq ($(PLATFORM),WINDOWS)
MISCLINKOPTS+= -Wl,--large-address-aware
@ -285,7 +285,7 @@ notice:
eduke32$(EXESUFFIX): $(GAMEOBJS) $(EOBJ)/$(ENGINELIB) $(JAUDIOLIBDIR)/$(JAUDIOLIB) $(ENETDIR)/$(ENETLIB) $(MISCGAMEDEPS)
$(LINK_STATUS)
if $(CC) $(CFLAGS) $(OURCFLAGS) -o $@ $^ $(LIBS) $(STDCPPLIB) $(MISCLINKOPTS); then $(LINK_OK); else $(LINK_FAILED); fi
if $(CC) $(CFLAGS) $(OURCONLYFLAGS) $(OURCFLAGS) -o $@ $^ $(LIBS) $(STDCPPLIB) $(MISCLINKOPTS); then $(LINK_OK); else $(LINK_FAILED); fi
ifeq (1,$(RELEASE))
ifeq (0,$(DEBUGANYWAY))
$(STRIP) eduke32$(EXESUFFIX)
@ -299,7 +299,7 @@ endif
mapster32$(EXESUFFIX): $(EDITOROBJS) $(EOBJ)/$(EDITORLIB) $(EOBJ)/$(ENGINELIB) $(JAUDIOLIBDIR)/$(JAUDIOLIB)
$(LINK_STATUS)
if $(CC) $(CFLAGS) $(OURCFLAGS) -o $@ $^ $(LIBS) $(STDCPPLIB) $(MISCLINKOPTS); then $(LINK_OK); else $(LINK_FAILED); fi
if $(CC) $(CFLAGS) $(OURCONLYFLAGS) $(OURCFLAGS) -o $@ $^ $(LIBS) $(STDCPPLIB) $(MISCLINKOPTS); then $(LINK_OK); else $(LINK_FAILED); fi
ifeq (1,$(RELEASE))
ifeq (0,$(DEBUGANYWAY))
$(STRIP) mapster32$(EXESUFFIX)
@ -359,11 +359,11 @@ $(OBJ)/%.$o: $(SRC)/%.nasm
$(OBJ)/%.$o: $(SRC)/%.c
$(COMPILE_STATUS)
if $(CC) $(CFLAGS) $(OURCFLAGS) -c $< -o $@; then $(COMPILE_OK); else $(COMPILE_FAILED); fi
if $(CC) $(CFLAGS) $(OURCONLYFLAGS) $(OURCFLAGS) -c $< -o $@; then $(COMPILE_OK); else $(COMPILE_FAILED); fi
$(OBJ)/%.$o: $(SRC)/lunatic/%.c
$(COMPILE_STATUS)
if $(CC) $(CFLAGS) $(OURCFLAGS) -c $< -o $@; then $(COMPILE_OK); else $(COMPILE_FAILED); fi
if $(CC) $(CFLAGS) $(OURCONLYFLAGS) $(OURCFLAGS) -c $< -o $@; then $(COMPILE_OK); else $(COMPILE_FAILED); fi
$(SRC)/lunatic/dynsymlist_osx: $(SRC)/lunatic/dynsymlist
sed 's/[{};]//g;s/[A-Za-z_][A-Za-z_0-9]*/_&/g' $< > $@
@ -377,15 +377,23 @@ $(SRC)/lunatic/eduke32.def: $(SRC)/lunatic/dynsymlist
$(OBJ)/%.$o: Apple/%.m
$(COMPILE_STATUS)
if $(CC) $(CFLAGS) $(OURCFLAGS) -c $< -o $@; then $(COMPILE_OK); else $(COMPILE_FAILED); fi
if $(CC) $(CFLAGS) $(OURCONLYFLAGS) $(OURCFLAGS) -c $< -o $@; then $(COMPILE_OK); else $(COMPILE_FAILED); fi
$(OBJ)/%.$o: $(SRC)/%.cc
$(COMPILE_STATUS)
if $(CXX) $(CXXFLAGS) $(OURCXXFLAGS) $(OURCFLAGS) -c $< -o $@; then $(COMPILE_OK); else $(COMPILE_FAILED); fi
$(OBJ)/%.$o: $(SRC)/%.cpp
$(COMPILE_STATUS)
if $(CXX) $(CXXFLAGS) $(OURCXXFLAGS) $(OURCFLAGS) -c $< -o $@; then $(COMPILE_OK); else $(COMPILE_FAILED); fi
$(OBJ)/%.$o: $(SRC)/%.cxx
$(COMPILE_STATUS)
if $(CXX) $(CXXFLAGS) $(OURCXXFLAGS) $(OURCFLAGS) -c $< -o $@; then $(COMPILE_OK); else $(COMPILE_FAILED); fi
$(OBJ)/%.$o: $(SRC)/jmact/%.c
$(COMPILE_STATUS)
if $(CC) $(CFLAGS) $(OURCFLAGS) -c $< -o $@; then $(COMPILE_OK); else $(COMPILE_FAILED); fi
if $(CC) $(CFLAGS) $(OURCONLYFLAGS) $(OURCFLAGS) -c $< -o $@; then $(COMPILE_OK); else $(COMPILE_FAILED); fi
$(OBJ)/%.$o: $(SRC)/misc/%.rc
$(COMPILE_STATUS)
@ -393,19 +401,19 @@ $(OBJ)/%.$o: $(SRC)/misc/%.rc
$(OBJ)/%.$o: $(SRC)/util/%.c
$(COMPILE_STATUS)
if $(CC) $(CFLAGS) $(OURCFLAGS) -c $< -o $@; then $(COMPILE_OK); else $(COMPILE_FAILED); fi
if $(CC) $(CFLAGS) $(OURCONLYFLAGS) $(OURCFLAGS) -c $< -o $@; then $(COMPILE_OK); else $(COMPILE_FAILED); fi
$(OBJ)/%.$o: $(RSRC)/%.c
$(COMPILE_STATUS)
if $(CC) $(CFLAGS) $(OURCFLAGS) -c $< -o $@; then $(COMPILE_OK); else $(COMPILE_FAILED); fi
if $(CC) $(CFLAGS) $(OURCONLYFLAGS) $(OURCFLAGS) -c $< -o $@; then $(COMPILE_OK); else $(COMPILE_FAILED); fi
$(OBJ)/game_banner.$o: $(RSRC)/game_banner.c
$(COMPILE_STATUS)
if $(CC) $(CFLAGS) $(OURCFLAGS) -Wno-pointer-sign -c $< -o $@; then $(COMPILE_OK); else $(COMPILE_FAILED); fi
if $(CC) $(CFLAGS) $(OURCONLYFLAGS) $(OURCFLAGS) -Wno-pointer-sign -c $< -o $@; then $(COMPILE_OK); else $(COMPILE_FAILED); fi
$(OBJ)/editor_banner.$o: $(RSRC)/editor_banner.c
$(COMPILE_STATUS)
if $(CC) $(CFLAGS) $(OURCFLAGS) -Wno-pointer-sign -c $< -o $@; then $(COMPILE_OK); else $(COMPILE_FAILED); fi
if $(CC) $(CFLAGS) $(OURCONLYFLAGS) $(OURCFLAGS) -Wno-pointer-sign -c $< -o $@; then $(COMPILE_OK); else $(COMPILE_FAILED); fi
$(RSRC)/game_banner.c: $(RSRC)/game.bmp
echo "#include <gdk-pixbuf/gdk-pixdata.h>" > $@

View file

@ -147,7 +147,7 @@ else
W_NO_UNUSED_RESULT :=
endif
BASECFLAGS=$(debug) -W -Wall -Wimplicit -Werror-implicit-function-declaration \
BASECFLAGS=$(debug) -W -Wall -Werror-implicit-function-declaration \
-funsigned-char -fno-strict-aliasing -DNO_GCC_BUILTINS -D_FORTIFY_SOURCE=2 \
$(F_JUMP_TABLES) $(W_NO_UNUSED_RESULT) $(ARCH) \
-Wextra #-Wwrite-strings -Waddress -Wlogical-op
@ -174,6 +174,7 @@ ifneq (0,$(DMALLOC))
BASECFLAGS+= -DDMALLOC
endif
BASECONLYFLAGS=-Wimplicit
BASECXXFLAGS= -fno-exceptions -fno-rtti
BASEASFLAGS=-s #-g

View file

@ -16,7 +16,7 @@ include ../Makefile.common
ifneq ($(DXROOT_OVERRIDE),)
DXROOT=$(DXROOT_OVERRIDE)
else
DXROOT=../sdk/dx
DXROOT=../../sdk/dx
#DXROOT=c:/sdks/directx/dx8
endif
FMODROOTWIN=c:/sdks/fmodapi374win/api
@ -48,6 +48,7 @@ else
endif
OURCFLAGS=$(BASECFLAGS) -Wno-char-subscripts -I$(INC) $(ARCH)
OURCONLYFLAGS=$(BASECONLYFLAGS)
OURCXXFLAGS=$(BASECXXFLAGS)
ASFLAGS=$(BASEASFLAGS)
@ -172,11 +173,20 @@ OURCFLAGS+= $(BUILDCFLAGS)
# TARGETS
UTILOBJS=$(OBJ)/kextract.$o $(OBJ)/kgroup.$o $(OBJ)/transpal.$o $(OBJ)/wad2art.$o $(OBJ)/wad2map.$o $(OBJ)/md2tool.$o \
$(OBJ)/generateicon.$o $(OBJ)/cacheinfo.$o $(OBJ)/arttool.$o $(OBJ)/givedepth.$o $(OBJ)/mkpalette.$o \
$(OBJ)/compat.$o $(OBJ)/pragmas.$o
UTILS=kextract$(EXESUFFIX) kgroup$(EXESUFFIX) transpal$(EXESUFFIX) wad2art$(EXESUFFIX) wad2map$(EXESUFFIX) md2tool$(EXESUFFIX)
UTILS=kextract$(EXESUFFIX) kgroup$(EXESUFFIX) transpal$(EXESUFFIX) wad2art$(EXESUFFIX) wad2map$(EXESUFFIX) md2tool$(EXESUFFIX) \
generateicon$(EXESUFFIX) cacheinfo$(EXESUFFIX) arttool$(EXESUFFIX) givedepth$(EXESUFFIX) mkpalette$(EXESUFFIX)
# all: $(OBJ)/$(ENGINELIB) $(OBJ)/$(EDITORLIB)
utils: $(UTILS)
utils: start $(UTILS) finish
start:
$(BUILD_STARTED)
finish:
$(BUILD_FINISHED)
@ls -l $(UTILS)
enginelib: $(OBJ)/$(ENGINELIB)
$(OBJ)/$(ENGINELIB): $(ENGINEOBJS)
@ -195,34 +205,40 @@ $(OBJ)/$(EDITORLIB): $(EDITOROBJS)
#pragmacheck$(EXESUFFIX): $(OBJ)/pragmacheck.$o $(OBJ)/pragmas.$o
# $(CC) $(subst -Dmain=app_main,,$(OURCFLAGS)) -o $@ $^
kextract$(EXESUFFIX): $(OBJ)/kextract.$o $(OBJ)/compat.$o $(UTILADDOBJS)
kextract$(EXESUFFIX): $(OBJ)/kextract.$o $(OBJ)/compat.$o $(OBJ)/compat_tools.$o $(UTILADDOBJS)
$(ONESTEP_STATUS)
if $(CC) -o $@ $^ $(UTILLIBS); then $(ONESTEP_OK); fi
kgroup$(EXESUFFIX): $(OBJ)/kgroup.$o $(OBJ)/compat.$o $(UTILADDOBJS)
kgroup$(EXESUFFIX): $(OBJ)/kgroup.$o $(OBJ)/compat.$o $(OBJ)/compat_tools.$o $(UTILADDOBJS)
$(ONESTEP_STATUS)
if $(CC) -o $@ $^ $(UTILLIBS); then $(ONESTEP_OK); fi
transpal$(EXESUFFIX): $(OBJ)/transpal.$o $(OBJ)/pragmas.$o $(OBJ)/compat.$o $(UTILADDOBJS)
transpal$(EXESUFFIX): $(OBJ)/transpal.$o $(OBJ)/pragmas.$o $(OBJ)/compat.$o $(OBJ)/compat_tools.$o $(UTILADDOBJS)
$(ONESTEP_STATUS)
if $(CC) -o $@ $^ $(UTILLIBS); then $(ONESTEP_OK); fi
wad2art$(EXESUFFIX): $(OBJ)/wad2art.$o $(OBJ)/pragmas.$o $(OBJ)/compat.$o $(UTILADDOBJS)
wad2art$(EXESUFFIX): $(OBJ)/wad2art.$o $(OBJ)/pragmas.$o $(OBJ)/compat.$o $(OBJ)/compat_tools.$o $(UTILADDOBJS)
$(ONESTEP_STATUS)
if $(CC) -o $@ $^ $(UTILLIBS); then $(ONESTEP_OK); fi
wad2map$(EXESUFFIX): $(OBJ)/wad2map.$o $(OBJ)/pragmas.$o $(OBJ)/compat.$o $(UTILADDOBJS)
wad2map$(EXESUFFIX): $(OBJ)/wad2map.$o $(OBJ)/pragmas.$o $(OBJ)/compat.$o $(OBJ)/compat_tools.$o $(UTILADDOBJS)
$(ONESTEP_STATUS)
if $(CC) -o $@ $^ $(UTILLIBS); then $(ONESTEP_OK); fi
md2tool$(EXESUFFIX): $(OBJ)/md2tool.$o $(OBJ)/compat.$o $(UTILADDOBJS)
md2tool$(EXESUFFIX): $(OBJ)/md2tool.$o $(OBJ)/compat.$o $(OBJ)/compat_tools.$o $(UTILADDOBJS)
$(ONESTEP_STATUS)
if $(CC) -o $@ $^ $(UTILLIBS); then $(ONESTEP_OK); fi
generateicon$(EXESUFFIX): $(OBJ)/generateicon.$o $(OBJ)/kplib.$o
generateicon$(EXESUFFIX): $(OBJ)/generateicon.$o $(OBJ)/compat.$o $(OBJ)/pragmas.$o $(OBJ)/kplib.$o $(OBJ)/cache1d.$o $(OBJ)/compat_tools.$o $(UTILADDOBJS)
$(ONESTEP_STATUS)
if $(CC) -o $@ $^ $(UTILLIBS); then $(ONESTEP_OK); fi
cacheinfo$(EXESUFFIX): $(OBJ)/cacheinfo.$o $(OBJ)/compat.$o $(UTILADDOBJS)
cacheinfo$(EXESUFFIX): $(OBJ)/cacheinfo.$o $(OBJ)/compat.$o $(OBJ)/compat_tools.$o $(UTILADDOBJS)
$(ONESTEP_STATUS)
if $(CC) -o $@ $^ $(UTILLIBS); then $(ONESTEP_OK); fi
enumdisplay$(EXESUFFIX): src/misc/enumdisplay.c
$(ONESTEP_STATUS)
if $(CC) -g -Os -o $@ $^ $(UTILLIBS) -I$(DXROOT)/include -lgdi32; then $(ONESTEP_OK); fi
mapdump$(EXESUFFIX): $(OBJ)/mapdump.$o
arttool$(EXESUFFIX): $(OBJ)/arttool.$o $(UTILADDOBJS)
$(ONESTEP_STATUS)
if $(CXX) -o $@ $^ $(UTILLIBS); then $(ONESTEP_OK); fi
givedepth$(EXESUFFIX): $(OBJ)/givedepth.$o $(UTILADDOBJS)
$(ONESTEP_STATUS)
if $(CC) -o $@ $^ $(UTILLIBS); then $(ONESTEP_OK); fi
mkpalette$(EXESUFFIX): $(OBJ)/mkpalette.$o $(UTILADDOBJS)
$(ONESTEP_STATUS)
if $(CC) -o $@ $^ $(UTILLIBS); then $(ONESTEP_OK); fi
@ -236,18 +252,23 @@ $(OBJ)/%.$o: $(SRC)/%.nasm
$(OBJ)/%.$o: $(SRC)/%.c
$(COMPILE_STATUS)
if $(CC) $(CFLAGS) $(OURCFLAGS) -c $< -o $@; then $(COMPILE_OK); else $(COMPILE_FAILED); fi
if $(CC) $(CFLAGS) $(OURCONLYFLAGS) $(OURCFLAGS) -c $< -o $@; then $(COMPILE_OK); else $(COMPILE_FAILED); fi
$(OBJ)/%.$o: $(SRC)/%.m
$(COMPILE_STATUS)
if $(CC) $(CFLAGS) $(OURCFLAGS) -c $< -o $@; then $(COMPILE_OK); else $(COMPILE_FAILED); fi
if $(CC) $(CFLAGS) $(OURCONLYFLAGS) $(OURCFLAGS) -c $< -o $@; then $(COMPILE_OK); else $(COMPILE_FAILED); fi
$(OBJ)/%.$o: $(SRC)/%.cc
$(COMPILE_STATUS)
if $(CXX) $(CXXFLAGS) $(OURCXXFLAGS) $(OURCFLAGS) -c $< -o $@; then $(COMPILE_OK); else $(COMPILE_FAILED); fi
$(OBJ)/%.$o: $(SRC)/%.cpp
$(COMPILE_STATUS)
if $(CXX) $(CXXFLAGS) $(OURCXXFLAGS) $(OURCFLAGS) -c $< -o $@; then $(COMPILE_OK); else $(COMPILE_FAILED); fi
$(OBJ)/%.$o: $(SRC)/%.cxx
$(CXX) $(CXXFLAGS) $(OURCXXFLAGS) $(OURCFLAGS) -c $< -o $@
$(COMPILE_STATUS)
if $(CXX) $(CXXFLAGS) $(OURCXXFLAGS) $(OURCFLAGS) -c $< -o $@; then $(COMPILE_OK); else $(COMPILE_FAILED); fi
$(OBJ)/%.$o: $(SRC)/misc/%.rc
$(COMPILE_STATUS)
@ -255,11 +276,23 @@ $(OBJ)/%.$o: $(SRC)/misc/%.rc
$(OBJ)/%.$o: $(SRC)/util/%.c
$(COMPILE_STATUS)
if $(CC) $(CFLAGS) $(OURCFLAGS) -c $< -o $@; then $(COMPILE_OK); else $(COMPILE_FAILED); fi
if $(CC) $(CFLAGS) $(OURCONLYFLAGS) $(OURCFLAGS) -c $< -o $@; then $(COMPILE_OK); else $(COMPILE_FAILED); fi
$(OBJ)/%.$o: $(SRC)/util/%.cc
$(COMPILE_STATUS)
if $(CXX) $(CXXFLAGS) $(OURCXXFLAGS) $(OURCFLAGS) -c $< -o $@; then $(COMPILE_OK); else $(COMPILE_FAILED); fi
$(OBJ)/%.$o: $(SRC)/util/%.cpp
$(COMPILE_STATUS)
if $(CXX) $(CXXFLAGS) $(OURCXXFLAGS) $(OURCFLAGS) -c $< -o $@; then $(COMPILE_OK); else $(COMPILE_FAILED); fi
$(OBJ)/%.$o: $(SRC)/util/%.cxx
$(COMPILE_STATUS)
if $(CXX) $(CXXFLAGS) $(OURCXXFLAGS) $(OURCFLAGS) -c $< -o $@; then $(COMPILE_OK); else $(COMPILE_FAILED); fi
$(OBJ)/%.$o: $(RSRC)/%.c
$(COMPILE_STATUS)
if $(CC) $(CFLAGS) $(OURCFLAGS) -c $< -o $@; then $(COMPILE_OK); else $(COMPILE_FAILED); fi
if $(CC) $(CFLAGS) $(OURCONLYFLAGS) $(OURCFLAGS) -c $< -o $@; then $(COMPILE_OK); else $(COMPILE_FAILED); fi
$(OBJ)/editor_banner.$o: $(RSRC)/editor_banner.c
echo "#include <gdk-pixbuf/gdk-pixdata.h>" > $@

View file

@ -38,10 +38,15 @@ $(OBJ)/startgtk.editor.$o: $(SRC)/startgtk.editor.c $(INC)/baselayer.h $(INC)/bu
$(OBJ)/build_icon.$o: $(RSRC)/build_icon.c
$(OBJ)/compat_tools.$o: $(SRC)/util/compat_tools.c
$(OBJ)/kextract.$o: $(SRC)/util/kextract.c $(INC)/compat.h
$(OBJ)/kgroup.$o: $(SRC)/util/kgroup.c $(INC)/compat.h
$(OBJ)/transpal.$o: $(SRC)/util/transpal.c $(INC)/compat.h $(INC)/pragmas.h
$(OBJ)/wad2art.$o: $(SRC)/util/wad2art.c $(INC)/compat.h $(INC)/pragmas.h
$(OBJ)/wad2map.$o: $(SRC)/util/wad2map.c $(INC)/compat.h $(INC)/pragmas.h
$(OBJ)/generateicon.$o: $(SRC)/util/generateicon.c
$(OBJ)/md2tool.$o: $(SRC)/util/md2tool.c $(INC)/compat.h $(INC)/build.h $(INC)/glbuild.h $(INC)/mdsprite.h
$(OBJ)/generateicon.$o: $(SRC)/util/generateicon.c $(INC)/kplib.h $(INC)/compat.h
$(OBJ)/cacheinfo.$o: $(SRC)/util/cacheinfo.c $(INC)/compat.h
$(OBJ)/arttool.$o: $(SRC)/util/arttool.cc
$(OBJ)/givedepth.$o: $(SRC)/util/givedepth.c
$(OBJ)/mkpalette.$o: $(SRC)/util/mkpalette.c

View file

@ -231,8 +231,8 @@ ifneq (0,$(NEDMALLOC))
endif
ifeq ($(PRETTY_OUTPUT),1)
BUILD_STARTED = printf "\033[K\033[1;36mBuild started using \"$(CC) $(OURCFLAGS)\"\033[0m\n"
BUILD_ECHOFLAGS = printf "\033[K\033[1;36mEnded compilation in this directory using \"$(CC) $(OURCFLAGS)\"\033[0m\n"
BUILD_STARTED = printf "\033[K\033[1;36mBuild started using \"$(CC) $(OURCFLAGS) $(OURCONLYFLAGS) $(OURCXXFLAGS)\"\033[0m\n"
BUILD_ECHOFLAGS = printf "\033[K\033[1;36mEnded compilation in this directory using \"$(CC) $(OURCFLAGS) $(OURCONLYFLAGS) $(OURCXXFLAGS)\"\033[0m\n"
BUILD_FINISHED = printf "\033[K\033[1;36mBuild successful:\033[0m\n"
COMPILE_STATUS = printf "\033[K\033[0mBuilding object \033[1m$@\033[0m...\033[0m\r"
ONESTEP_STATUS = printf "\033[K\033[0mBuilding executable \033[1m$@\033[0m...\033[0m\r"

View file

@ -121,7 +121,6 @@ void setmousepresscallback(void (*callback)(int32_t,int32_t));
void setjoypresscallback(void (*callback)(int32_t,int32_t));
const char *getkeyname(int32_t num);
const char *getjoyname(int32_t what, int32_t num); // what: 0=axis, 1=button, 2=hat
char *Bstrtolower(char *str);
char bgetchar(void);
#define bkbhit() (keyasciififoplc != keyasciififoend)

View file

@ -592,6 +592,7 @@ int32_t Bcanonicalisefilename(char *filename, int32_t removefn);
char *Bgetsystemdrives(void);
int32_t Bfilelength(int32_t fd);
char *Bstrtoken(char *s, const char *delim, char **ptrptr, int32_t chop);
char *Bstrtolower(char *str);
int32_t Bwildmatch (const char *i, const char *j);
#if !defined(_WIN32)

View file

@ -139,26 +139,6 @@ struct glinfo_t glinfo =
};
#endif
char *Bstrtolower(char *str)
{
if (!str) return NULL;
{
int32_t i = 0, len = Bstrlen(str);
if (len <= 0) return str;
do
{
*(str+i) = Btolower(*(str+i));
i++;
}
while (--len);
}
return str;
}
int32_t flushlogwindow = 1;
static void onvideomodechange(int32_t newmode) { UNREFERENCED_PARAMETER(newmode); }

View file

@ -736,6 +736,26 @@ char *Bstrtoken(char *s, const char *delim, char **ptrptr, int32_t chop)
return start;
}
char *Bstrtolower(char *str)
{
if (!str) return NULL;
{
int32_t i = 0, len = Bstrlen(str);
if (len <= 0) return str;
do
{
*(str+i) = Btolower(*(str+i));
i++;
}
while (--len);
}
return str;
}
//Brute-force case-insensitive, slash-insensitive, * and ? wildcard matcher
//Given: string i and string j. string j can have wildcards
@ -809,14 +829,12 @@ uint32_t Bgetsysmemsize(void)
if (aGlobalMemoryStatusEx(&memst))
siz = (uint32_t)min(UINT_MAX, memst.ullTotalPhys);
}
/*
else
{
// Yeah, there's enough Win9x hatred here that a perfectly good workaround
// has been replaced by an error message. Oh well, we don't support 9x anyway.
// initprintf("Bgetsysmemsize(): error determining system memory size!\n");
initprintf("Bgetsysmemsize(): error determining system memory size!\n");
}
*/
FreeLibrary(lib);
}

View file

@ -0,0 +1,930 @@
/**
* BUILD ART file editing tool
* @author Jonathon Fowler
* @license Artistic License 2.0 (http://www.perlfoundation.org/artistic_license_2_0)
*/
#include <iostream>
#include <fstream>
#include <cstring>
#include <string>
#include <cstdlib>
using namespace std;
void usage()
{
cout << "BUILD ART file editing tool" << endl;
cout << "Copyright (C) 2008 Jonathon Fowler <jf@jonof.id.au>" << endl;
cout << "Released under the Artistic License 2.0" << endl;
cout << endl;
cout << " arttool create [options]" << endl;
cout << " -f <filenum> Selects which numbered ART file to create (default 0)" << endl;
cout << " -o <offset> Specifies the first tile in the file (default 0)" << endl;
cout << " -n <ntiles> The number of tiles for the art file (default 256)" << endl;
cout << " Creates an empty ART file named 'tilesXXX.art'" << endl;
cout << endl;
cout << " arttool addtile [options] <tilenum> <filename>" << endl;
cout << " -x <pixels> X-centre" << endl;
cout << " -y <pixels> Y-centre" << endl;
cout << " -ann <frames> Animation frame span" << endl;
cout << " -ant <type> Animation type (0=none, 1=oscillate, 2=forward, 3=reverse)" << endl;
cout << " -ans <speed> Animation speed" << endl;
cout << " Adds a tile to the 'tilesXXX.art' set from a TGA or PCX source" << endl;
cout << endl;
cout << " arttool rmtile <tilenum>" << endl;
cout << " Removes a tile from the 'tilesXXX.art' set" << endl;
cout << endl;
cout << " arttool tileprop [options] <tilenum>" << endl;
cout << " -x <pixels> X-centre" << endl;
cout << " -y <pixels> Y-centre" << endl;
cout << " -ann <frames> Animation frame span, may be -ve" << endl;
cout << " -ant <type> Animation type (0=none, 1=oscillate, 2=forward, 3=reverse)" << endl;
cout << " -ans <speed> Animation speed" << endl;
cout << " Changes tile properties" << endl;
cout << endl;
}
class ARTFile {
private:
string filename_;
long localtilestart_;
long localtileend_;
short * tilesizx_;
short * tilesizy_;
long * picanm_;
// for removing or replacing tile data
int markprelength_, markskiplength_, markpostlength_;
char * insert_;
int insertlen_;
void writeShort(ofstream &ofs, short s)
{
char d[2] = { s&255, (s>>8)&255 };
ofs.write(d, 2);
}
void writeLong(ofstream &ofs, long l)
{
char d[4] = { l&255, (l>>8)&255, (l>>16)&255, (l>>24)&255 };
ofs.write(d, 4);
}
short readShort(ifstream &ifs)
{
unsigned char d[2];
unsigned short s;
ifs.read((char *) d, 2);
s = (unsigned short)d[0];
s |= (unsigned short)d[1] << 8;
return (short)s;
}
long readLong(ifstream &ifs)
{
unsigned char d[4];
unsigned long l;
ifs.read((char *) d, 4);
l = (unsigned long)d[0];
l |= (unsigned long)d[1] << 8;
l |= (unsigned long)d[2] << 16;
l |= (unsigned long)d[3] << 24;
return (long)l;
}
void dispose()
{
if (tilesizx_) delete [] tilesizx_;
if (tilesizy_) delete [] tilesizy_;
if (picanm_) delete [] picanm_;
if (insert_) delete [] insert_;
insert_ = 0;
insertlen_ = 0;
}
void load()
{
ifstream infile(filename_.c_str(), ios::in | ios::binary);
int i, ntiles;
if (infile.is_open()) {
do {
if (readLong(infile) != 1) {
break;
}
readLong(infile); // skip the numtiles
dispose();
localtilestart_ = readLong(infile);
localtileend_ = readLong(infile);
ntiles = localtileend_ - localtilestart_ + 1;
tilesizx_ = new short[ntiles];
tilesizy_ = new short[ntiles];
picanm_ = new long[ntiles];
for (i = 0; i < ntiles; i++) {
tilesizx_[i] = readShort(infile);
}
for (i = 0; i < ntiles; i++) {
tilesizy_[i] = readShort(infile);
}
for (i = 0; i < ntiles; i++) {
picanm_[i] = readLong(infile);
}
} while (0);
infile.close();
}
}
public:
ARTFile(string filename)
: filename_(filename), localtilestart_(0), localtileend_(-1),
tilesizx_(0), tilesizy_(0), picanm_(0),
markprelength_(0), markskiplength_(0), markpostlength_(0),
insert_(0), insertlen_(0)
{
load();
}
~ARTFile()
{
dispose();
}
/**
* Sets up for an empty file
* @param start the starting tile
* @param ntiles the number of tiles total
*/
void init(int start, int ntiles)
{
dispose();
localtilestart_ = start;
localtileend_ = start + ntiles - 1;
tilesizx_ = new short[ntiles];
tilesizy_ = new short[ntiles];
picanm_ = new long[ntiles];
memset(tilesizx_, 0, sizeof(short)*ntiles);
memset(tilesizy_, 0, sizeof(short)*ntiles);
memset(picanm_, 0, sizeof(long)*ntiles);
markprelength_ = 0;
markskiplength_ = 0;
markpostlength_ = 0;
insert_ = 0;
insertlen_ = 0;
}
/**
* Returns the number of tiles in the loaded file
* @return 0 means no file loaded
*/
int getNumTiles()
{
return (localtileend_ - localtilestart_ + 1);
}
int getFirstTile()
{
return localtilestart_;
}
int getLastTile()
{
return localtileend_;
}
void removeTile(int tile)
{
int i, end;
if (tile < localtilestart_ || tile > localtileend_) {
return;
}
end = localtileend_ - tile;
tile -= localtilestart_;
markprelength_ = markpostlength_ = 0;
for (i = 0; i < tile; i++) {
markprelength_ += tilesizx_[i] * tilesizy_[i];
}
markskiplength_ = tilesizx_[tile] * tilesizy_[tile];
for (i = tile + 1; i <= end; i++) {
markpostlength_ += tilesizx_[i] * tilesizy_[i];
}
tilesizx_[tile] = tilesizy_[tile] = 0;
}
void replaceTile(int tile, char * replace, int replacelen)
{
if (tile < localtilestart_ || tile > localtileend_) {
return;
}
removeTile(tile);
insert_ = replace;
insertlen_ = replacelen;
}
void setTileSize(int tile, int x, int y)
{
if (tile < localtilestart_ || tile > localtileend_) {
return;
}
tile -= localtilestart_;
tilesizx_[tile] = x;
tilesizy_[tile] = y;
}
void setXOfs(int tile, int x)
{
if (tile < localtilestart_ || tile > localtileend_) {
return;
}
tile -= localtilestart_;
picanm_[tile] &= ~(255<<8);
picanm_[tile] |= ((long)((unsigned char)x) << 8);
}
void setYOfs(int tile, int y)
{
if (tile < localtilestart_ || tile > localtileend_) {
return;
}
tile -= localtilestart_;
picanm_[tile] &= ~(255<<16);
picanm_[tile] |= ((long)((unsigned char)y) << 16);
}
void setAnimType(int tile, int type)
{
if (tile < localtilestart_ || tile > localtileend_) {
return;
}
tile -= localtilestart_;
picanm_[tile] &= ~(3<<6);
picanm_[tile] |= ((long)(type&3) << 6);
}
void setAnimFrames(int tile, int frames)
{
if (tile < localtilestart_ || tile > localtileend_) {
return;
}
tile -= localtilestart_;
picanm_[tile] &= ~(63);
picanm_[tile] |= ((long)(frames&63));
}
void setAnimSpeed(int tile, int speed)
{
if (tile < localtilestart_ || tile > localtileend_) {
return;
}
tile -= localtilestart_;
picanm_[tile] &= ~(15<<24);
picanm_[tile] |= ((long)(speed&15) << 24);
}
int write()
{
string tmpfilename(filename_ + ".arttooltmp");
ofstream outfile(tmpfilename.c_str(), ios::out | ios::trunc | ios::binary);
ifstream infile(filename_.c_str(), ios::in | ios::binary);
int i, left;
char blk[4096];
if (!infile.is_open() && (markprelength_ > 0 || markskiplength_ > 0 || markpostlength_ > 0)) {
return -1; // couldn't open the original file for copying
} else if (infile.is_open()) {
// skip to the start of the existing ART data
int ofs = 4+4+4+4+(2+2+4)*(localtileend_-localtilestart_+1);
infile.seekg(ofs, ios::cur);
}
// write a header to the temporary file
writeLong(outfile, 1); // version
writeLong(outfile, 0); // numtiles
writeLong(outfile, localtilestart_);
writeLong(outfile, localtileend_);
for (int i = 0; i < localtileend_ - localtilestart_ + 1; i++) {
writeShort(outfile, tilesizx_[i]);
}
for (int i = 0; i < localtileend_ - localtilestart_ + 1; i++) {
writeShort(outfile, tilesizy_[i]);
}
for (int i = 0; i < localtileend_ - localtilestart_ + 1; i++) {
writeLong(outfile, picanm_[i]);
}
// copy the existing leading tile data to be kept
left = markprelength_;
while (left > 0) {
i = left;
if (i > sizeof(blk)) {
i = sizeof(blk);
}
infile.read(blk, i);
outfile.write(blk, i);
left -= i;
}
// insert the replacement data
if (insertlen_ > 0) {
outfile.write(insert_, insertlen_);
}
if (markskiplength_ > 0) {
infile.seekg(markskiplength_, ios::cur);
}
// copy the existing trailing tile data to be kept
left = markpostlength_;
while (left > 0) {
i = left;
if (i > sizeof(blk)) {
i = sizeof(blk);
}
infile.read(blk, i);
outfile.write(blk, i);
left -= i;
}
// close our files
if (infile.is_open()) {
infile.close();
}
outfile.close();
// replace it with the new one
unlink(filename_.c_str());
rename(tmpfilename.c_str(), filename_.c_str());
return 0;
}
};
/**
* Decodes a PCX file directly to BUILD's column-major pixel order
* @param data the raw file data
* @param datalen the length of the raw file data
* @param imgdata receives a pointer to the decoded image data
* @param imgdataw receives the decoded image width
* @param imgdatah receives the decoded image height
* @return 0 on success, 1 if the format is invalid
*/
int loadimage_pcx(unsigned char * data, int datalen, char ** imgdata, int& imgdataw, int& imgdatah)
{
if (data[0] != 10 ||
data[1] != 5 ||
data[2] != 1 ||
data[3] != 8 ||
data[64] != 0 ||
data[65] != 1) {
return 1;
}
int bpl = data[66] + ((int)data[67] << 8);
int x, y, repeat, colour;
unsigned char *wptr, *rptr;
imgdataw = (data[8] + ((int)data[9] << 8)) - (data[4] + ((int)data[5] << 8)) + 1;
imgdatah = (data[10] + ((int)data[11] << 8)) - (data[6] + ((int)data[7] << 8)) + 1;
*imgdata = new char [imgdataw * imgdatah];
rptr = data + 128;
for (y = 0; y < imgdatah; y++) {
wptr = (unsigned char *) (*imgdata + y);
x = 0;
do {
repeat = *(rptr++);
if ((repeat & 192) == 192) {
colour = *(rptr++);
repeat = repeat & 63;
} else {
colour = repeat;
repeat = 1;
}
for (; repeat > 0; repeat--, x++) {
if (x < imgdataw) {
*wptr = (unsigned char) colour;
wptr += imgdatah; // next column
}
}
} while (x < bpl);
}
return 0;
}
/**
* Loads a tile from a picture file into memory
* @param filename the filename
* @param imgdata receives a pointer to the decoded image data
* @param imgdataw receives the decoded image width
* @param imgdatah receives the decoded image height
* @return 0 on success
*/
int loadimage(string filename, char ** imgdata, int& imgdataw, int& imgdatah)
{
ifstream infile(filename.c_str(), ios::in | ios::binary);
unsigned char * data = 0;
int datalen = 0, err = 0;
if (!infile.is_open()) {
return 1;
}
infile.seekg(0, ios::end);
datalen = infile.tellg();
infile.seekg(0, ios::beg);
data = new unsigned char [datalen];
infile.read((char *) data, datalen);
infile.close();
err = loadimage_pcx(data, datalen, imgdata, imgdataw, imgdatah);
delete [] data;
return err;
}
class Operation {
protected:
string makefilename(int n)
{
string filename("tilesXXX.art");
filename[5] = '0' + (n / 100) % 10;
filename[6] = '0' + (n / 10) % 10;
filename[7] = '0' + (n / 1) % 10;
return filename;
}
public:
typedef enum {
NO_ERROR = 0,
ERR_BAD_OPTION = 1,
ERR_BAD_VALUE = 2,
ERR_TOO_MANY_PARAMS = 3,
ERR_NO_ART_FILE = 4,
ERR_INVALID_IMAGE = 5,
} Result;
static char const * const translateResult(Result r)
{
switch (r) {
case NO_ERROR: return "no error";
case ERR_BAD_OPTION: return "bad option";
case ERR_BAD_VALUE: return "bad value";
case ERR_TOO_MANY_PARAMS: return "too many parameters given";
case ERR_NO_ART_FILE: return "no ART file was found";
case ERR_INVALID_IMAGE: return "a corrupt or unrecognised image was given";
default: return "unknown error";
}
}
virtual ~Operation()
{
}
/**
* Sets an option
* @param opt the option name
* @param value the option value
* @return a value from the Result enum
*/
virtual Result setOption(string opt, string value) = 0;
/**
* Sets a parameter from the unnamed sequence
* @param number the parameter number
* @param value the parameter value
* @return a value from the Result enum
*/
virtual Result setParameter(int number, string value) = 0;
/**
* Do the operation
* @return a value from the Result enum
*/
virtual Result perform() = 0;
};
class CreateOp : public Operation {
private:
int filen_, offset_, ntiles_;
public:
CreateOp() : filen_(0), offset_(0), ntiles_(256) { }
virtual Result setOption(string opt, string value)
{
if (opt == "f") {
filen_ = atoi(value.c_str());
if (filen_ < 0 || filen_ > 999) {
return ERR_BAD_VALUE;
}
} else if (opt == "o") {
offset_ = atoi(value.c_str());
if (offset_ < 0) {
return ERR_BAD_VALUE;
}
} else if (opt == "n") {
ntiles_ = atoi(value.c_str());
if (ntiles_ < 1) {
return ERR_BAD_VALUE;
}
} else {
return ERR_BAD_OPTION;
}
return NO_ERROR;
}
virtual Result setParameter(int number, string value)
{
return ERR_TOO_MANY_PARAMS;
}
virtual Result perform()
{
ARTFile art(makefilename(filen_));
art.init(offset_, ntiles_);
art.write();
return NO_ERROR;
}
};
class AddTileOp : public Operation {
private:
int xofs_, yofs_;
int animframes_, animtype_, animspeed_;
int tilenum_;
string filename_;
public:
AddTileOp()
: xofs_(0), yofs_(0),
animframes_(0), animtype_(0), animspeed_(0),
tilenum_(-1), filename_("")
{ }
virtual Result setOption(string opt, string value)
{
if (opt == "x") {
xofs_ = atoi(value.c_str());
} else if (opt == "y") {
yofs_ = atoi(value.c_str());
} else if (opt == "ann") {
animframes_ = atoi(value.c_str());
if (animframes_ < 0 || animframes_ > 63) {
return ERR_BAD_VALUE;
}
} else if (opt == "ant") {
animtype_ = atoi(value.c_str());
if (animtype_ < 0 || animtype_ > 3) {
return ERR_BAD_VALUE;
}
} else if (opt == "ans") {
animspeed_ = atoi(value.c_str());
if (animspeed_ < 0 || animspeed_ > 15) {
return ERR_BAD_VALUE;
}
} else {
return ERR_BAD_OPTION;
}
return NO_ERROR;
}
virtual Result setParameter(int number, string value)
{
switch (number) {
case 0:
tilenum_ = atoi(value.c_str());
return NO_ERROR;
case 1:
filename_ = value;
return NO_ERROR;
default:
return ERR_TOO_MANY_PARAMS;
}
}
virtual Result perform()
{
int tilesperfile = 0, nextstart = 0;
int filenum = 0;
char * imgdata = 0;
int imgdatalen = 0, imgdataw = 0, imgdatah = 0;
// open the first art file to get the file size used by default
{
ARTFile art(makefilename(0));
tilesperfile = art.getNumTiles();
if (tilesperfile == 0) {
return ERR_NO_ART_FILE;
}
}
// load the tile image into memory
switch (loadimage(filename_, &imgdata, imgdataw, imgdatah)) {
case 0: break; // win
default: return ERR_INVALID_IMAGE;
}
// open art files until we find one that encompasses the range we need
// and when we find it, make the change
for (filenum = 0; filenum < 1000; filenum++) {
ARTFile art(makefilename(filenum));
bool dirty = false, done = false;
if (art.getNumTiles() == 0) {
// no file exists, so we treat it as though it does
art.init(nextstart, tilesperfile);
dirty = true;
}
if (tilenum_ >= art.getFirstTile() && tilenum_ <= art.getLastTile()) {
art.replaceTile(tilenum_, imgdata, imgdataw * imgdatah);
art.setTileSize(tilenum_, imgdataw, imgdatah);
art.setXOfs(tilenum_, xofs_);
art.setYOfs(tilenum_, yofs_);
art.setAnimFrames(tilenum_, animframes_);
art.setAnimSpeed(tilenum_, animspeed_);
art.setAnimType(tilenum_, animtype_);
done = true;
dirty = true;
imgdata = 0; // ARTFile.replaceTile took ownership of the pointer
}
nextstart += art.getNumTiles();
if (dirty) {
art.write();
}
if (done) {
return NO_ERROR;
}
}
if (imgdata) {
delete [] imgdata;
}
return ERR_NO_ART_FILE;
}
};
class RmTileOp : public Operation {
private:
int tilenum_;
public:
RmTileOp() : tilenum_(-1) { }
virtual Result setOption(string opt, string value)
{
return ERR_BAD_OPTION;
}
virtual Result setParameter(int number, string value)
{
switch (number) {
case 0:
tilenum_ = atoi(value.c_str());
return NO_ERROR;
default:
return ERR_TOO_MANY_PARAMS;
}
}
virtual Result perform()
{
int filenum = 0;
// open art files until we find one that encompasses the range we need
// and when we find it, remove the tile
for (filenum = 0; filenum < 1000; filenum++) {
ARTFile art(makefilename(filenum));
if (art.getNumTiles() == 0) {
// no file exists, so give up
break;
}
if (tilenum_ >= art.getFirstTile() && tilenum_ <= art.getLastTile()) {
art.removeTile(tilenum_);
art.write();
return NO_ERROR;
}
}
return ERR_NO_ART_FILE;
}
};
class TilePropOp : public Operation {
private:
int xofs_, yofs_;
int animframes_, animtype_, animspeed_;
int tilenum_;
int settings_;
enum {
SET_XOFS = 1,
SET_YOFS = 2,
SET_ANIMFRAMES = 4,
SET_ANIMTYPE = 8,
SET_ANIMSPEED = 16,
};
public:
TilePropOp()
: xofs_(0), yofs_(0),
animframes_(0), animtype_(0), animspeed_(0),
tilenum_(-1), settings_(0)
{ }
virtual Result setOption(string opt, string value)
{
if (opt == "x") {
xofs_ = atoi(value.c_str());
settings_ |= SET_XOFS;
} else if (opt == "y") {
yofs_ = atoi(value.c_str());
settings_ |= SET_YOFS;
} else if (opt == "ann") {
animframes_ = atoi(value.c_str());
settings_ |= SET_ANIMFRAMES;
if (animframes_ < 0 || animframes_ > 63) {
return ERR_BAD_VALUE;
}
} else if (opt == "ant") {
animtype_ = atoi(value.c_str());
settings_ |= SET_ANIMTYPE;
if (animtype_ < 0 || animtype_ > 3) {
return ERR_BAD_VALUE;
}
} else if (opt == "ans") {
animspeed_ = atoi(value.c_str());
settings_ |= SET_ANIMSPEED;
if (animspeed_ < 0 || animspeed_ > 15) {
return ERR_BAD_VALUE;
}
} else {
return ERR_BAD_OPTION;
}
return NO_ERROR;
}
virtual Result setParameter(int number, string value)
{
switch (number) {
case 0:
tilenum_ = atoi(value.c_str());
return NO_ERROR;
default:
return ERR_TOO_MANY_PARAMS;
}
}
virtual Result perform()
{
int filenum = 0;
if (settings_ == 0) {
return NO_ERROR;
}
// open art files until we find one that encompasses the range we need
// and when we find it, make the change
for (filenum = 0; filenum < 1000; filenum++) {
ARTFile art(makefilename(filenum));
if (art.getNumTiles() == 0) {
// no file exists, so give up
break;
}
if (tilenum_ >= art.getFirstTile() && tilenum_ <= art.getLastTile()) {
if (settings_ & SET_XOFS) {
art.setXOfs(tilenum_, xofs_);
}
if (settings_ & SET_YOFS) {
art.setYOfs(tilenum_, yofs_);
}
if (settings_ & SET_ANIMFRAMES) {
art.setAnimFrames(tilenum_, animframes_);
}
if (settings_ & SET_ANIMSPEED) {
art.setAnimSpeed(tilenum_, animspeed_);
}
if (settings_ & SET_ANIMTYPE) {
art.setAnimType(tilenum_, animtype_);
}
art.write();
return NO_ERROR;
}
}
return ERR_NO_ART_FILE;
}
};
int main(int argc, char ** argv)
{
int showusage = 0;
Operation * oper = 0;
Operation::Result err;
if (argc < 2) {
showusage = 1;
} else {
string opt(argv[1]);
string value;
// create the option handler object according to the first param
if (opt == "create") {
oper = new CreateOp;
} else if (opt == "addtile") {
oper = new AddTileOp;
} else if (opt == "rmtile") {
oper = new RmTileOp;
} else if (opt == "tileprop") {
oper = new TilePropOp;
} else {
showusage = 2;
}
// apply the command line options given
if (oper) {
int unnamedParm = 0;
for (int i = 2; i < argc && !showusage; i++) {
if (argv[i][0] == '-') {
opt = string(argv[i]).substr(1);
if (i+1 >= argc) {
showusage = 2;
break;
}
value = string(argv[i+1]);
i++;
switch (err = oper->setOption(opt, value)) {
case Operation::NO_ERROR: break;
default:
cerr << "error: " << Operation::translateResult(err) << endl;
showusage = 2;
break;
}
} else {
value = string(argv[i]);
switch (oper->setParameter(unnamedParm, value)) {
case Operation::NO_ERROR: break;
default:
cerr << "error: " << Operation::translateResult(err) << endl;
showusage = 2;
break;
}
unnamedParm++;
}
}
}
}
if (showusage) {
usage();
if (oper) delete oper;
return (showusage - 1);
} else if (oper) {
err = oper->perform();
delete oper;
switch (err) {
case Operation::NO_ERROR: return 0;
default:
cerr << "error: " << Operation::translateResult(err) << endl;
return 1;
}
}
return 0;
}

View file

@ -22,7 +22,7 @@ char source[MAXPATH], output[MAXPATH], bytesize;
int PathAddExt(char *path, char *ext);
void main(int argc, char *argv[])
int main(int argc, char *argv[])
{
printf("BIN2C - Binary to C data converter\n"
"Copyright (c) 1999 Jonathon Fowler\n\n");
@ -133,6 +133,8 @@ void main(int argc, char *argv[])
fclose(out);
fclose(in);
return 0;
}

View file

@ -0,0 +1,16 @@
// Compatibility declarations for the tools to avoid linking to the entire engine.
#include "compat.h"
//
// initprintf() -- prints a string
//
void initprintf(const char *f, ...)
{
va_list va;
char buf[2048];
va_start(va, f);
Bvsnprintf(buf, sizeof(buf), f, va);
va_end(va);
}

View file

@ -0,0 +1,103 @@
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#define MAXNUMTILES 256
int artversion, numtiles;
int localtilestart, localtileend;
short tilesizx[MAXNUMTILES], tilesizy[MAXNUMTILES];
int picanm[MAXNUMTILES];
FILE * openartfile(char *fn)
{
FILE *fh;
fh = fopen(fn,"rb");
if (!fh) return NULL;
fread(&artversion,4,1,fh); if (artversion != 1) { puts("Bad art version"); goto fail; }
fread(&numtiles,4,1,fh);
fread(&localtilestart,4,1,fh);
fread(&localtileend,4,1,fh);
numtiles = localtileend-localtilestart+1;
if (numtiles > MAXNUMTILES) { puts("Too many tiles"); goto fail; }
fread(tilesizx,2,numtiles,fh);
fread(tilesizy,2,numtiles,fh);
fread(picanm,4,numtiles,fh);
return fh;
fail:
fclose(fh);
return NULL;
}
int main(int argc, char **argv)
{
char *palfile = "palette.dat", *voxfile = "output.vox";
int tilenum;
int depth;
FILE *artfh, *voxfh, *palfh;
int tilesz;
unsigned char palette[768];
unsigned char *tiledata;
int i;
if (argc < 4) {
puts("givedepth <artfile.art> <tilenum> <depth> [palette.dat] [output.vox]");
return 0;
}
tilenum = atoi(argv[2]);
depth = atoi(argv[3]);
if (argc >= 4) palfile = argv[4];
if (argc >= 5) voxfile = argv[5];
palfh = fopen(palfile,"rb");
if (!palfh) {
puts("Failure opening palette file");
return 1;
}
fread(palette,768,1,palfh);
fclose(palfh);
artfh = openartfile(argv[1]);
if (!artfh) {
puts("Failure opening art file");
return 1;
}
if (tilenum < 0 || tilenum > numtiles) {
puts("Tilenum out of range in art file");
fclose(artfh);
return 1;
}
for (i=0; i<tilenum; i++) fseek(artfh, tilesizx[i] * tilesizy[i], SEEK_CUR);
tilesz = tilesizx[tilenum]*tilesizy[tilenum];
tiledata = (unsigned char *)malloc(tilesz);
if (!tiledata) {
puts("Could not allocate memory for tile");
fclose(artfh);
return 1;
}
fread(tiledata, tilesz, 1, artfh);
fclose(artfh);
voxfh = fopen(voxfile,"wb");
if (!voxfh) {
puts("Could not create output file");
free(tiledata);
return 1;
}
fwrite(&depth,4,1,voxfh);
fwrite(&tilesizx[tilenum],4,1,voxfh);
fwrite(&tilesizy[tilenum],4,1,voxfh);
for (i=0; i<depth; i++) {
fwrite(tiledata,tilesz,1,voxfh);
}
fwrite(palette,768,1,voxfh);
free(tiledata);
}

View file

@ -0,0 +1,253 @@
#include <stdio.h>
#include <string.h>
#include <math.h>
struct hsv {
float h, s, v;
};
struct rgb {
float r, g, b;
};
struct gradient {
int start, len, chompends;
struct hsv startcolour, endcolour;
};
float min2(float x, float y);
float max2(float x, float y);
void convertHSVtoRGB(struct hsv *hsv, struct rgb *rgb);
int showusage(void);
int readscript(char *fn);
struct gradient ramps[256];
int nramps = 0;
int main(int argc, char **argv)
{
struct hsv palette[256], lerpstep, lerped;
struct rgb rgbidx;
unsigned char rgbout[3];
int idx, step, rampnum;
FILE* fh;
char *outfile = "palette.dat";
memset(palette,0,sizeof(palette));
if (argc < 2) return showusage();
if (readscript(argv[1])) return 1;
if (argc >= 3) outfile = argv[2];
for (rampnum = 0; rampnum < nramps; rampnum++) {
idx = ramps[rampnum].start;
step = ramps[rampnum].len;
if (ramps[rampnum].chompends & 1) step++;
if (ramps[rampnum].chompends & 2) step++;
lerpstep.h = (ramps[rampnum].endcolour.h - ramps[rampnum].startcolour.h) / (float)step;
lerpstep.s = (ramps[rampnum].endcolour.s - ramps[rampnum].startcolour.s) / (float)step;
lerpstep.v = (ramps[rampnum].endcolour.v - ramps[rampnum].startcolour.v) / (float)step;
lerped = ramps[rampnum].startcolour;
if (ramps[rampnum].chompends & 1) {
step--;
lerped.h += lerpstep.h;
lerped.s += lerpstep.s;
lerped.v += lerpstep.v;
}
if (ramps[rampnum].chompends & 2) step--;
for (; step > 0; step--,idx++) {
palette[idx].h = lerped.h;
palette[idx].s = lerped.s;
palette[idx].v = lerped.v;
lerped.h += lerpstep.h;
lerped.s += lerpstep.s;
lerped.v += lerpstep.v;
}
}
fh = fopen(outfile,"wb");
if (!fh) return 1;
for (idx=0; idx<256; idx++) {
convertHSVtoRGB(&palette[idx], &rgbidx);
//printf("Index %d: r=%g g=%g b=%g\n",idx,rgbidx.r,rgbidx.g,rgbidx.b);
rgbout[0] = (unsigned char)min2(255,max2(0,(int)(rgbidx.r * 255.0))) >> 2;
rgbout[1] = (unsigned char)min2(255,max2(0,(int)(rgbidx.g * 255.0))) >> 2;
rgbout[2] = (unsigned char)min2(255,max2(0,(int)(rgbidx.b * 255.0))) >> 2;
fwrite(rgbout,3,1,fh);
}
fclose(fh);
return 0;
}
float min2(float x, float y)
{
return x < y ? x : y;
}
float max2(float x, float y)
{
return x > y ? x : y;
}
// http://www.cs.rit.edu/~ncs/color/t_convert.html
void convertHSVtoRGB(struct hsv *hsv, struct rgb *rgb)
{
int i;
float f, p, q, t;
if( hsv->s == 0 ) {
// achromatic (grey)
rgb->r = rgb->g = rgb->b = hsv->v;
return;
}
hsv->h /= 60; // sector 0 to 5
i = floor( hsv->h );
f = hsv->h - i; // factorial part of h
p = hsv->v * ( 1 - hsv->s );
q = hsv->v * ( 1 - hsv->s * f );
t = hsv->v * ( 1 - hsv->s * ( 1 - f ) );
switch( i ) {
case 0:
rgb->r = hsv->v;
rgb->g = t;
rgb->b = p;
break;
case 1:
rgb->r = q;
rgb->g = hsv->v;
rgb->b = p;
break;
case 2:
rgb->r = p;
rgb->g = hsv->v;
rgb->b = t;
break;
case 3:
rgb->r = p;
rgb->g = q;
rgb->b = hsv->v;
break;
case 4:
rgb->r = t;
rgb->g = p;
rgb->b = hsv->v;
break;
default: // case 5:
rgb->r = hsv->v;
rgb->g = p;
rgb->b = q;
break;
}
}
int showusage(void)
{
puts("mkpalette <palettescript.txt> [outputfile]");
puts("If outputfile is not given, palette.dat is assumed");
puts("\nPalette script format:\n"
" A line beginning with # is a comment, otherwise each line contains none\n"
"values separated by spaces defining the gradient:\n"
"\n"
" startindex rangesize skip starthue startsat startval endhue endsat endval\n"
"\n"
"Any text after the end of a gradient description is ignored, so may use it\n"
"to describe the colour.\n"
"\n"
"* 'startindex' specifies the first palette index to write to\n"
"* 'rangesize' specifies the length of the gradient\n"
"* 'skip' specifies whether the first and/or last elements of the range should\n"
" be ignored and with 'rangesize' elements interpolated between. This is so\n"
" you can have a gradient starting at (potentially) pure black and ending at\n"
" (potentially) pure white but without wasting a palette index on those colours\n"
" if they already exist, eg. in a grey ramp.\n"
" Legal values are 0 (no skipping), 1 (skip start), 2 (skip end),\n"
" or 3 (skip start and end).\n"
"* 'starthue', 'startsat', 'startval' are integers specifying the beginning\n"
" colour in Hue-Saturation-Value format.\n"
" 'starthue' should be in the range 0-360 indicating a degrees value\n"
" 'startsat' should be in the range 0-100 indicating a saturation percentage\n"
" 'startval' should be in the range 0-100 indicating an intensity percentage\n"
"* 'endhue', 'endsat', 'endval' specify the ending colour."
);
return 0;
}
int readscript(char *fn)
{
int start, len, skip, shue, ssat, sval, ehue, esat, eval;
FILE *fp;
char line[1024];
fp = fopen(fn,"rt");
if (!fp) {
puts("Error opening palette script");
return 1;
}
while (fgets(line,sizeof(line),fp)) {
{
// test for comment
char *p = line;
while (*p && (*p == ' ' || *p == '\t')) p++;
if (*p == '#') continue;
}
if (sscanf(line, "%d %d %d %d %d %d %d %d %d", &start,&len,&skip,&shue,&ssat,&sval,&ehue,&esat,&eval) < 9)
continue;
if (start < 0 || start > 255) {
printf("start index of %d is out of range 0-255\n", start);
continue;
}
if (len < 1 || len > 255) {
printf("length %d is out of range 1-255\n", len);
continue;
}
if (skip != (skip&3)) {
printf("skip value of %d is out of range 0-3\n", skip);
continue;
}
if (shue < 0 || shue > 360) {
printf("start hue %d is out of range 0-360\n", shue);
continue;
}
if (ssat < 0 || ssat > 100) {
printf("start saturation %d is out of range 0-100\n", ssat);
continue;
}
if (sval < 0 || sval > 100) {
printf("start value %d is out of range 0-100\n", sval);
continue;
}
if (ehue < 0 || ehue > 360) {
printf("end hue %d is out of range 0-360\n", shue);
continue;
}
if (esat < 0 || esat > 100) {
printf("end saturation %d is out of range 0-100\n", ssat);
continue;
}
if (eval < 0 || eval > 100) {
printf("end value %d is out of range 0-100\n", sval);
continue;
}
ramps[nramps].start = start;
ramps[nramps].len = len;
ramps[nramps].chompends = skip;
ramps[nramps].startcolour.h = (float)shue;
ramps[nramps].startcolour.s = (float)ssat / 100.0;
ramps[nramps].startcolour.v = (float)sval / 100.0;
ramps[nramps].endcolour.h = (float)ehue;
ramps[nramps].endcolour.s = (float)esat / 100.0;
ramps[nramps].endcolour.v = (float)eval / 100.0;
nramps++;
}
fclose(fp);
return 0;
}

View file

@ -6,7 +6,7 @@
#include <dos.h>
#include <stdio.h>
void main(void)
int main(void)
{
int font, width, height, numchars;
struct REGPACK r;
@ -136,4 +136,5 @@ void main(void)
}
} while (font != 6);
return 0;
}

View file

@ -9,6 +9,8 @@ INC=include
CFLAGS=$(BASECFLAGS) $(BUILDCFLAGS) $(F_NO_STACK_PROTECTOR)
# for BUILD_ECHOFLAGS:
OURCFLAGS=$(CFLAGS)
OURCONLYFLAGS=$(BASECONLYFLAGS)
OURCXXFLAGS=$(BASECXXFLAGS)
CPPFLAGS=-I$(INC) -I$(SRC) -I../../$(EROOT)/include
@ -38,7 +40,7 @@ $(OBJNAME): $(OBJECTS)
$(OBJECTS): $(OBJ)/%.o: $(SRC)/%.c $(INC)/enet/*.h
-mkdir -p $(OBJ)
$(COMPILE_STATUS)
if $(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@; then $(COMPILE_OK); else $(COMPILE_FAILED); fi
if $(CC) $(CPPFLAGS) $(OURCONLYFLAGS) $(OURCFLAGS) -c $< -o $@; then $(COMPILE_OK); else $(COMPILE_FAILED); fi
ifeq ($(PRETTY_OUTPUT),1)
.SILENT:

View file

@ -10,12 +10,15 @@ INC=include
ifneq ($(DXROOT_OVERRIDE),)
DXROOT ?= $(DXROOT_OVERRIDE)
else
DXROOT ?= c:/sdks/directx/dx8
DXROOT=../../../sdk/dx
#DXROOT ?= c:/sdks/directx/dx8
endif
CFLAGS=$(BASECFLAGS) $(BUILDCFLAGS) $(F_NO_STACK_PROTECTOR)
# for BUILD_ECHOFLAGS:
OURCFLAGS=$(CFLAGS)
OURCONLYFLAGS=$(BASECONLYFLAGS)
OURCXXFLAGS=$(BASECXXFLAGS)
CPPFLAGS=-I$(INC) -I$(SRC) -DHAVE_VORBIS
ifeq ($(PLATFORM),DARWIN)
@ -59,7 +62,7 @@ $(OBJNAME): $(OBJECTS)
$(OBJECTS): $(OBJ)/%.o: $(SRC)/%.c
-mkdir -p $(OBJ)
$(COMPILE_STATUS)
if $(CC) $(CPPFLAGS) $(OURCFLAGS) -c $< -o $@; then $(COMPILE_OK); else $(COMPILE_FAILED); fi
if $(CC) $(CPPFLAGS) $(OURCONLYFLAGS) $(OURCFLAGS) -c $< -o $@; then $(COMPILE_OK); else $(COMPILE_FAILED); fi
ifeq ($(PRETTY_OUTPUT),1)
.SILENT: