diff --git a/default.bam b/default.bam index 8ae9b3f01..ccdb1819f 100644 --- a/default.bam +++ b/default.bam @@ -61,6 +61,11 @@ function dc_data(output, data, script) return os.execute(dc_compiler .. " " .. data .. " " .. script .. " -d " .. output) end +function dc_cdata(output, data, script) + print("dc_cdata " .. PathFilename(output) .. " = " .. PathFilename(data) .. " ~ " .. PathFilename(script)) + return os.execute(dc_compiler .. " " .. data .. " " .. script .. " -c " .. output) +end + function Dat2c(datafile, sourcefile, arrayname) datafile = Path(datafile) sourcefile = Path(sourcefile) @@ -77,7 +82,7 @@ function DataCompile(datafile, scriptfile, headerfile, sourcefile, outputdatafil outputdatafile = Path(outputdatafile) bam_add_job("dc_source", sourcefile, datafile, scriptfile) bam_add_job("dc_header", headerfile, datafile, scriptfile) - bam_add_job("dc_data", outputdatafile, datafile, scriptfile) + bam_add_job("dc_cdata", outputdatafile, datafile, scriptfile) bam_add_dependency(sourcefile, datafile) bam_add_dependency(sourcefile, scriptfile) bam_add_dependency(sourcefile, headerfile) @@ -85,7 +90,7 @@ function DataCompile(datafile, scriptfile, headerfile, sourcefile, outputdatafil bam_add_dependency(headerfile, scriptfile) bam_add_dependency(outputdatafile, datafile) bam_add_dependency(outputdatafile, scriptfile) - return {data = outputdatafile, header=headerfile, source=sourcefile} + return {cdata = outputdatafile, header=headerfile, source=sourcefile} end config_name = "debug" @@ -117,10 +122,23 @@ baselib.apply(server_settings, "network") settings.cc.includes:add("src") settings.cc.includes:add("../baselib/src/external/zlib") -serverdata = DataCompile("datasrc/teewars.ds", "datasrc/server.dts", "src/game/server/data.h", "src/game/server/data/server_data.cpp", "data/server.dat") -clientdata = DataCompile("datasrc/teewars.ds", "datasrc/client.dts", "src/game/client/data.h", "src/game/client/data/client_data.cpp", "data/client.dat") -internal_clientdata = Dat2c("data/client.dat", "src/game/client/data/client_internal.cpp", "internal_client_data"); -internal_serverdata = Dat2c("data/server.dat", "src/game/server/data/server_internal.cpp", "internal_server_data"); +serverdata = DataCompile( + "datasrc/teewars.ds", + "datasrc/server.dts", + "src/game/server/data.h", + "src/game/server/data/server_data.cpp", + "src/game/server/data/server_internal.cpp") + +clientdata = DataCompile( + "datasrc/teewars.ds", + "datasrc/client.dts", + "src/game/client/data.h", + "src/game/client/data/server_data.cpp", + "src/game/client/data/server_internal.cpp") + +--clientdata = DataCompile("datasrc/teewars.ds", "datasrc/client.dts", "src/game/client/data.h", "src/game/client/data/client_data.cpp", "datasrc/client.dat") +--internal_clientdata = Dat2c("datasrc/client.dat", "src/game/client/data/client_internal.cpp", "internal_client_data"); +--internal_serverdata = Dat2c("datasrc/server.dat", "src/game/server/data/server_internal.cpp", "internal_server_data"); function build(config) engine = Compile(settings, Collect("src/engine/*.cpp")) @@ -128,8 +146,8 @@ function build(config) server = Compile(settings, Collect("src/engine/server/*.cpp")) masterserver = Compile(settings, Collect("src/mastersrv/*.cpp")) game_shared = Compile(settings, Collect("src/game/*.cpp")) - game_client = Compile(settings, Collect("src/game/client/*.cpp"), clientdata.source, internal_clientdata) - game_server = Compile(settings, Collect("src/game/server/*.cpp"), serverdata.source, internal_serverdata) + game_client = Compile(settings, Collect("src/game/client/*.cpp"), clientdata.source, clientdata.cdata) + game_server = Compile(settings, Collect("src/game/server/*.cpp"), serverdata.source, serverdata.cdata) editor = Compile(settings, Collect("src/editor/*.cpp")) -- build tools @@ -146,8 +164,8 @@ function build(config) server_exe = Link(server_settings, "teewars_srv"..config_ext, engine, server, game_shared, game_server) masterserver_exe = Link(server_settings, "mastersrv"..config_ext, masterserver, engine) - Target(PseudoTarget("client", client_exe, clientdata.data)) - Target(PseudoTarget("server", server_exe, serverdata.data)) + Target(PseudoTarget("client", client_exe)) + Target(PseudoTarget("server", server_exe)) Target(PseudoTarget("masterserver", masterserver_exe)) Target(PseudoTarget("tools", tools)) end diff --git a/scripts/compiler.py b/scripts/compiler.py index 5d6a814ad..daa74e95d 100755 --- a/scripts/compiler.py +++ b/scripts/compiler.py @@ -465,7 +465,8 @@ class translator: for s in self.structs: s.emit_header_code(out) print >>out, "" - print >>out, "data_container *load_data_container(const char *filename);" + print >>out, "data_container *load_data_from_file(const char *filename);" + print >>out, "data_container *load_data_from_memory(unsigned char *filename);" print >>out, "" @@ -485,9 +486,18 @@ static void patch_ptr(char **ptr, char *base) for s in self.structs: s.emit_source_code(out) print >>out, ''' -data_container *load_data_container(const char *filename) + +data_container *load_data_from_memory(unsigned char *mem) { - data_container *con = 0; + /* patch all pointers */ + data_container *con = (data_container*)mem; + patch_ptr_data_container(con, (char *)con); + return con; +} + +data_container *load_data_from_file(const char *filename) +{ + unsigned char *data = 0; int size; /* open file */ @@ -499,13 +509,11 @@ data_container *load_data_container(const char *filename) fseek(f, 0, SEEK_SET); /* allocate, read data and close file */ - con = (data_container*)malloc(size); - fread(con, 1, size, f); + data = (unsigned char *)malloc(size); + fread(data, 1, size, f); fclose(f); - /* patch all pointers */ - patch_ptr_data_container(con, (char *)con); - return con; + return load_data_from_memory(data); } ''' @@ -571,6 +579,7 @@ input_filename = sys.argv[1] script_filename = sys.argv[2] output_filename = 0 +coutput_filename = 0 header_filename = 0 source_filename = 0 @@ -580,6 +589,8 @@ elif sys.argv[3] == '-s': source_filename = sys.argv[4] elif sys.argv[3] == '-d': output_filename = sys.argv[4] +elif sys.argv[3] == '-c': + coutput_filename = sys.argv[4] srcdata = parse_file(input_filename) script = parse_file(script_filename) @@ -594,4 +605,22 @@ if source_filename: if output_filename: rawdata = translator.emit_data() file(output_filename, "wb").write(rawdata) - #print "filesize:", len(rawdata) +if coutput_filename: + i = 0 + rawdata = translator.emit_data() + f = file(coutput_filename, "w") + + print >>f,"unsigned char internal_data[] = {" + print >>f,str(ord(rawdata[0])), + for d in rawdata[1:]: + s = ","+str(ord(d)) + print >>f,s, + i += len(s)+1 + + if i >= 70: + print >>f,"" + i = 0 + print >>f,"" + print >>f,"};" + print >>f,"" + f.close() diff --git a/scripts/dat2c.py b/scripts/dat2c.py index 87dfd114e..09517ca5a 100644 --- a/scripts/dat2c.py +++ b/scripts/dat2c.py @@ -3,7 +3,7 @@ import sys data = file(sys.argv[1], "rb").read() i = 0 -print "const char", sys.argv[2], "[] = {" +print "unsigned char", sys.argv[2], "[] = {" print str(ord(data[0])), for d in data[1:]: s = ","+str(ord(d)) diff --git a/src/game/client/game_client.cpp b/src/game/client/game_client.cpp index e5d874d22..d29c6b7d1 100644 --- a/src/game/client/game_client.cpp +++ b/src/game/client/game_client.cpp @@ -422,10 +422,12 @@ static const int killmsg_max = 5; killmsg killmsgs[killmsg_max]; static int killmsg_current = 0; +extern unsigned char internal_data[]; + void modc_init() { // load the data container - data = load_data_container("data/client.dat"); + data = load_data_from_memory(internal_data); // load sounds for(int s = 0; s < data->num_sounds; s++) diff --git a/src/game/client/mapres_tilemap.cpp b/src/game/client/mapres_tilemap.cpp index 197a1a8b8..357e8870a 100644 --- a/src/game/client/mapres_tilemap.cpp +++ b/src/game/client/mapres_tilemap.cpp @@ -49,7 +49,6 @@ void tilemap_render(float scale, int fg) float frac = (1.0f/1024.0f);//2.0f; //2.0f; float texsize = 1024.0f; float nudge = 0.5f/texsize; - float s = 1.0f; for(int y = 0; y < tmap->height; y++) for(int x = 0; x < tmap->width; x++) @@ -80,7 +79,6 @@ void tilemap_render(float scale, int fg) int py0 = ty*(1024/16); int px1 = (tx+1)*(1024/16)-1; int py1 = (ty+1)*(1024/16)-1; - float z = -5.0f; gfx_quads_setsubset( nudge + px0/texsize+frac, diff --git a/src/game/server/game_server.cpp b/src/game/server/game_server.cpp index e063364c1..9fb50d4b4 100644 --- a/src/game/server/game_server.cpp +++ b/src/game/server/game_server.cpp @@ -1652,9 +1652,11 @@ void mods_message(int msg, int client_id) } } +extern unsigned char internal_data[]; + void mods_init() { - data = load_data_container("data/server.dat"); + data = load_data_from_memory(internal_data); col_init(32); int start, num;