mirror of
https://github.com/ddnet/ddnet.git
synced 2024-09-20 01:24:18 +00:00
Merge branch 'master' of git://github.com/oy/teeworlds into HEAD
Conflicts: bam.lua src/engine/console.h src/engine/server.h src/engine/server/server.cpp src/engine/shared/config.h src/engine/shared/config_variables.h src/engine/shared/console.cpp src/engine/shared/console.h src/game/client/components/binds.cpp src/game/client/components/chat.h src/game/client/components/console.cpp src/game/client/components/console.h src/game/client/components/controls.cpp src/game/client/components/emoticon.h src/game/client/components/maplayers.cpp src/game/client/components/menus.h src/game/client/components/scoreboard.h src/game/client/components/spectator.h src/game/client/components/voting.h src/game/client/gameclient.cpp src/game/client/gameclient.h src/game/client/render.h src/game/collision.cpp src/game/editor/ed_layer_tiles.cpp src/game/gamecore.cpp src/game/gamecore.h src/game/layers.cpp src/game/layers.h src/game/mapitems.h src/game/server/entities/character.cpp src/game/server/entities/laser.cpp src/game/server/entities/laser.h src/game/server/entities/pickup.cpp src/game/server/entities/pickup.h src/game/server/entities/projectile.cpp src/game/server/gamecontext.cpp src/game/server/gamecontroller.cpp src/game/server/gamecontroller.h src/game/server/gameworld.cpp src/game/server/gameworld.h src/game/server/player.cpp src/game/variables.h
This commit is contained in:
commit
0df6d0541f
42
bam.lua
42
bam.lua
|
@ -23,17 +23,17 @@ end
|
|||
|
||||
function CHash(output, ...)
|
||||
local inputs = TableFlatten({...})
|
||||
|
||||
|
||||
output = Path(output)
|
||||
|
||||
|
||||
-- compile all the files
|
||||
local cmd = Script("scripts/cmd5.py") .. " "
|
||||
for index, inname in ipairs(inputs) do
|
||||
cmd = cmd .. Path(inname) .. " "
|
||||
cmd = cmd .. Path(inname) .. " "
|
||||
end
|
||||
|
||||
|
||||
cmd = cmd .. " > " .. output
|
||||
|
||||
|
||||
AddJob(output, "cmd5 " .. output, cmd)
|
||||
for index, inname in ipairs(inputs) do
|
||||
AddDependency(output, inname)
|
||||
|
@ -73,7 +73,7 @@ function Dat2c(datafile, sourcefile, arrayname)
|
|||
AddJob(
|
||||
sourcefile,
|
||||
"dat2c " .. PathFilename(sourcefile) .. " = " .. PathFilename(datafile),
|
||||
Script("scripts/dat2c.py").. "\" " .. sourcefile .. " " .. datafile .. " " .. arrayname
|
||||
Script("scripts/dat2c.py").. "\" " .. sourcefile .. " " .. datafile .. " " .. arrayname
|
||||
)
|
||||
AddDependency(sourcefile, datafile)
|
||||
return sourcefile
|
||||
|
@ -85,7 +85,7 @@ function ContentCompile(action, output)
|
|||
output,
|
||||
action .. " > " .. output,
|
||||
--Script("datasrc/compile.py") .. "\" ".. Path(output) .. " " .. action
|
||||
Script("datasrc/compile.py") .. " " .. action .. " > " .. Path(output)
|
||||
Script("datasrc/compile.py") .. " " .. action .. " > " .. Path(output)
|
||||
)
|
||||
AddDependency(output, Path("datasrc/content.py")) -- do this more proper
|
||||
AddDependency(output, Path("datasrc/network.py"))
|
||||
|
@ -155,7 +155,7 @@ function build(settings)
|
|||
settings.cc.includes:Add("other/mysql/include")
|
||||
|
||||
if family == "unix" then
|
||||
if platform == "macosx" then
|
||||
if platform == "macosx" then
|
||||
settings.link.frameworks:Add("Carbon")
|
||||
settings.link.frameworks:Add("AppKit")
|
||||
else
|
||||
|
@ -168,7 +168,7 @@ function build(settings)
|
|||
settings.link.libs:Add("ole32")
|
||||
settings.link.libs:Add("shell32")
|
||||
end
|
||||
|
||||
|
||||
-- compile zlib if needed
|
||||
if config.zlib.value == 1 then
|
||||
settings.link.libs:Add("z")
|
||||
|
@ -184,7 +184,7 @@ function build(settings)
|
|||
-- build the small libraries
|
||||
wavpack = Compile(settings, Collect("src/engine/external/wavpack/*.c"))
|
||||
pnglite = Compile(settings, Collect("src/engine/external/pnglite/*.c"))
|
||||
|
||||
|
||||
-- build game components
|
||||
engine_settings = settings:Copy()
|
||||
server_settings = engine_settings:Copy()
|
||||
|
@ -199,10 +199,10 @@ function build(settings)
|
|||
|
||||
if platform == "macosx" then
|
||||
client_settings.link.frameworks:Add("OpenGL")
|
||||
client_settings.link.frameworks:Add("AGL")
|
||||
client_settings.link.frameworks:Add("Carbon")
|
||||
client_settings.link.frameworks:Add("Cocoa")
|
||||
launcher_settings.link.frameworks:Add("Cocoa")
|
||||
client_settings.link.frameworks:Add("AGL")
|
||||
client_settings.link.frameworks:Add("Carbon")
|
||||
client_settings.link.frameworks:Add("Cocoa")
|
||||
launcher_settings.link.frameworks:Add("Cocoa")
|
||||
if not string.find(settings.config_name, "nosql") then
|
||||
if arch == "amd64" then
|
||||
server_settings.link.libpath:Add("other/mysql/mac/lib64")
|
||||
|
@ -222,7 +222,7 @@ function build(settings)
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
elseif family == "windows" then
|
||||
client_settings.link.libs:Add("opengl32")
|
||||
client_settings.link.libs:Add("glu32")
|
||||
|
@ -237,11 +237,11 @@ function build(settings)
|
|||
config.sdl:Apply(client_settings)
|
||||
-- apply freetype settings
|
||||
config.freetype:Apply(client_settings)
|
||||
|
||||
|
||||
engine = Compile(engine_settings, Collect("src/engine/shared/*.cpp", "src/base/*.c"))
|
||||
client = Compile(client_settings, Collect("src/engine/client/*.cpp"))
|
||||
server = Compile(server_settings, Collect("src/engine/server/*.cpp"))
|
||||
|
||||
|
||||
versionserver = Compile(settings, Collect("src/versionsrv/*.cpp"))
|
||||
masterserver = Compile(settings, Collect("src/mastersrv/*.cpp"))
|
||||
banmaster = Compile(settings, Collect("src/banmaster/*.cpp"))
|
||||
|
@ -259,13 +259,13 @@ function build(settings)
|
|||
client_osxlaunch = Compile(client_settings, "src/osxlaunch/client.m")
|
||||
server_osxlaunch = Compile(launcher_settings, "src/osxlaunch/server.m")
|
||||
end
|
||||
|
||||
|
||||
tools = {}
|
||||
for i,v in ipairs(tools_src) do
|
||||
toolname = PathFilename(PathBase(v))
|
||||
tools[i] = Link(settings, toolname, Compile(settings, v), engine, zlib, pnglite)
|
||||
end
|
||||
|
||||
|
||||
-- build client, server, version server and master server
|
||||
client_exe = Link(client_settings, "DDRace", game_shared, game_client,
|
||||
engine, client, game_editor, zlib, pnglite, wavpack,
|
||||
|
@ -278,7 +278,7 @@ function build(settings)
|
|||
if platform == "macosx" then
|
||||
serverlaunch = Link(launcher_settings, "serverlaunch", server_osxlaunch)
|
||||
end
|
||||
|
||||
|
||||
versionserver_exe = Link(server_settings, "versionsrv", versionserver,
|
||||
engine, zlib)
|
||||
|
||||
|
@ -357,7 +357,7 @@ else
|
|||
release_nosql_settings.cc.defines:Add("CONF_RELEASE")
|
||||
end
|
||||
|
||||
if platform == "macosx" and arch == "ia32" then
|
||||
if platform == "macosx" and arch == "ia32" then
|
||||
debug_settings_ppc = debug_settings:Copy()
|
||||
debug_settings_ppc.config_name = "debug_ppc"
|
||||
debug_settings_ppc.config_ext = "_ppc_d"
|
||||
|
|
|
@ -10,12 +10,12 @@ function NewConfig(on_configured_callback)
|
|||
config.OnConfigured = function(self)
|
||||
return true
|
||||
end
|
||||
|
||||
|
||||
if on_configured_callback then config.OnConfigured = on_configured_callback end
|
||||
|
||||
|
||||
config.options = {}
|
||||
config.settings = NewSettings()
|
||||
|
||||
|
||||
config.NewSettings = function(self)
|
||||
local s = NewSettings()
|
||||
for _,v in pairs(self.options) do
|
||||
|
@ -28,25 +28,25 @@ function NewConfig(on_configured_callback)
|
|||
table.insert(self.options, o)
|
||||
self[o.name] = o
|
||||
end
|
||||
|
||||
|
||||
config.Print = function(self)
|
||||
for k,v in pairs(self.options) do
|
||||
print(v:FormatDisplay())
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
config.Save = function(self, filename)
|
||||
print("saved configuration to '"..filename.."'")
|
||||
local file = io.open(filename, "w")
|
||||
|
||||
|
||||
-- Define a little helper function to save options
|
||||
local saver = {}
|
||||
saver.file = file
|
||||
|
||||
|
||||
saver.line = function(self, str)
|
||||
self.file:write(str .. "\n")
|
||||
end
|
||||
|
||||
|
||||
saver.option = function(self, option, name)
|
||||
local valuestr = "no"
|
||||
if type(option[name]) == type(0) then
|
||||
|
@ -64,30 +64,30 @@ function NewConfig(on_configured_callback)
|
|||
self.file:write(option.name.."."..name.." = ".. valuestr.."\n")
|
||||
end
|
||||
|
||||
-- Save all the options
|
||||
-- Save all the options
|
||||
for k,v in pairs(self.options) do
|
||||
v:Save(saver)
|
||||
end
|
||||
file:close()
|
||||
end
|
||||
|
||||
|
||||
config.Load = function(self, filename)
|
||||
local options_func = loadfile(filename)
|
||||
local options_table = {}
|
||||
|
||||
|
||||
if not options_func then
|
||||
print("auto configuration")
|
||||
self:Config(filename)
|
||||
options_func = loadfile(filename)
|
||||
end
|
||||
|
||||
|
||||
if options_func then
|
||||
-- Setup the options tables
|
||||
for k,v in pairs(self.options) do
|
||||
options_table[v.name] = {}
|
||||
end
|
||||
setfenv(options_func, options_table)
|
||||
|
||||
|
||||
-- this is to make sure that we get nice error messages when
|
||||
-- someone sets an option that isn't valid.
|
||||
local mt = {}
|
||||
|
@ -96,8 +96,8 @@ function NewConfig(on_configured_callback)
|
|||
if v ~= nil then return v end
|
||||
error("there is no configuration option named '" .. key .. "'")
|
||||
end
|
||||
|
||||
setmetatable(options_table, mt)
|
||||
|
||||
setmetatable(options_table, mt)
|
||||
|
||||
-- Process the options
|
||||
options_func()
|
||||
|
@ -117,10 +117,10 @@ function NewConfig(on_configured_callback)
|
|||
print("run 'bam config' to generate")
|
||||
print("run 'bam config help' for configuration options")
|
||||
print("")
|
||||
os.exit(1)
|
||||
os.exit(1)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
config.Config = function(self, filename)
|
||||
print("")
|
||||
print("configuration:")
|
||||
|
@ -140,7 +140,7 @@ function NewConfig(on_configured_callback)
|
|||
end
|
||||
print("")
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
config.Autodetect = function(self)
|
||||
|
@ -159,7 +159,7 @@ function NewConfig(on_configured_callback)
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
config.Finalize = function(self, filename)
|
||||
if _bam_targets[0] == "config" then
|
||||
if _bam_targets[1] == "help" then
|
||||
|
@ -171,11 +171,11 @@ function NewConfig(on_configured_callback)
|
|||
|
||||
os.exit(0)
|
||||
end
|
||||
|
||||
|
||||
self:Load(filename)
|
||||
bam_update_globalstamp(filename)
|
||||
end
|
||||
|
||||
|
||||
return config
|
||||
end
|
||||
|
||||
|
@ -214,10 +214,10 @@ function MakeOption(name, value, check, save, display, printhelp)
|
|||
o.auto_detected = true
|
||||
o.FormatDisplay = function(self)
|
||||
local a = "SET"
|
||||
if self.auto_detected then a = "AUTO" end
|
||||
if self.auto_detected then a = "AUTO" end
|
||||
return string.format("%-5s %-20s %s", a, self.name, self:Display())
|
||||
end
|
||||
|
||||
|
||||
o.Display = display
|
||||
o.PrintHelp = printhelp
|
||||
if o.Display == nil then o.Display = DefaultOptionDisplay end
|
||||
|
@ -244,16 +244,16 @@ function OptTestCompileC(name, source, compileoptions, desc)
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
local save = function(option, output)
|
||||
output:option(option, "value")
|
||||
end
|
||||
|
||||
|
||||
local printhelp = function(option)
|
||||
print("\t"..option.name.."=on|off")
|
||||
if option.desc then print("\t\t"..option.desc) end
|
||||
end
|
||||
|
||||
|
||||
local o = MakeOption(name, false, check, save, nil, printhelp)
|
||||
o.desc = desc
|
||||
o.source = source
|
||||
|
@ -275,16 +275,16 @@ function OptToggle(name, default_value, desc)
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
local save = function(option, output)
|
||||
output:option(option, "value")
|
||||
end
|
||||
|
||||
|
||||
local printhelp = function(option)
|
||||
print("\t"..option.name.."=on|off")
|
||||
if option.desc then print("\t\t"..option.desc) end
|
||||
end
|
||||
|
||||
|
||||
local o = MakeOption(name, default_value, check, save, nil, printhelp)
|
||||
o.desc = desc
|
||||
return o
|
||||
|
@ -297,16 +297,16 @@ function OptInteger(name, default_value, desc)
|
|||
option.value = tonumber(ScriptArgs[option.name])
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
local save = function(option, output)
|
||||
output:option(option, "value")
|
||||
end
|
||||
|
||||
|
||||
local printhelp = function(option)
|
||||
print("\t"..option.name.."=N")
|
||||
if option.desc then print("\t\t"..option.desc) end
|
||||
end
|
||||
|
||||
|
||||
local o = MakeOption(name, default_value, check, save, nil, printhelp)
|
||||
o.desc = desc
|
||||
return o
|
||||
|
@ -320,16 +320,16 @@ function OptString(name, default_value, desc)
|
|||
option.value = ScriptArgs[option.name]
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
local save = function(option, output)
|
||||
output:option(option, "value")
|
||||
end
|
||||
|
||||
|
||||
local printhelp = function(option)
|
||||
print("\t"..option.name.."=STRING")
|
||||
if option.desc then print("\t\t"..option.desc) end
|
||||
end
|
||||
|
||||
|
||||
local o = MakeOption(name, default_value, check, save, nil, printhelp)
|
||||
o.desc = desc
|
||||
return o
|
||||
|
@ -354,7 +354,7 @@ function OptCCompiler(name, default_driver, default_c, default_cxx, desc)
|
|||
if ScriptArgs[option.name..".cxx"] then
|
||||
option.cxx_compiler = ScriptArgs[option.name..".cxx"]
|
||||
end
|
||||
|
||||
|
||||
option.auto_detected = false
|
||||
elseif option.driver then
|
||||
-- no need todo anything if we have a driver
|
||||
|
@ -379,11 +379,11 @@ function OptCCompiler(name, default_driver, default_c, default_cxx, desc)
|
|||
else
|
||||
error(option.driver.." is not a known c/c++ compile driver")
|
||||
end
|
||||
|
||||
|
||||
if option.c_compiler then settings.cc.c_compiler = option.c_compiler end
|
||||
if option.cxx_compiler then settings.cc.cxx_compiler = option.cxx_compiler end
|
||||
end
|
||||
|
||||
|
||||
local save = function(option, output)
|
||||
output:option(option, "driver")
|
||||
output:option(option, "c_compiler")
|
||||
|
@ -407,7 +407,7 @@ function OptCCompiler(name, default_driver, default_c, default_cxx, desc)
|
|||
if option.cxx_compiler then s = s .. " cxx="..option.cxx_compiler end
|
||||
return s
|
||||
end
|
||||
|
||||
|
||||
local o = MakeOption(name, nil, check, save, display, printhelp)
|
||||
o.desc = desc
|
||||
o.driver = false
|
||||
|
@ -430,7 +430,7 @@ function OptLibrary(name, header, desc)
|
|||
local check = function(option, settings)
|
||||
option.value = false
|
||||
option.include_path = false
|
||||
|
||||
|
||||
local function check_compile_include(filename, paths)
|
||||
if CTestCompile(settings, "#include <" .. filename .. ">\nint main(){return 0;}", "") then
|
||||
return ""
|
||||
|
@ -441,7 +441,7 @@ function OptLibrary(name, header, desc)
|
|||
return v
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
return false
|
||||
end
|
||||
|
||||
|
@ -468,12 +468,12 @@ function OptLibrary(name, header, desc)
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
local save = function(option, output)
|
||||
output:option(option, "value")
|
||||
output:option(option, "include_path")
|
||||
end
|
||||
|
||||
|
||||
local display = function(option)
|
||||
if option.value then
|
||||
if option.include_path then
|
||||
|
@ -490,7 +490,7 @@ function OptLibrary(name, header, desc)
|
|||
print("\t"..option.name.."=disable|system|PATH")
|
||||
if option.desc then print("\t\t"..option.desc) end
|
||||
end
|
||||
|
||||
|
||||
local o = MakeOption(name, false, check, save, display, printhelp)
|
||||
o.include_path = false
|
||||
o.header = header
|
||||
|
|
BIN
data/audio/music_menu.wv
Normal file
BIN
data/audio/music_menu.wv
Normal file
Binary file not shown.
|
@ -657,5 +657,14 @@ no limit
|
|||
|
||||
##### needs translation #####
|
||||
|
||||
Play background music
|
||||
==
|
||||
|
||||
Spectate next
|
||||
==
|
||||
|
||||
Spectate previous
|
||||
==
|
||||
|
||||
##### old translations #####
|
||||
|
||||
|
|
|
@ -657,6 +657,15 @@ no limit
|
|||
|
||||
##### needs translation #####
|
||||
|
||||
Play background music
|
||||
==
|
||||
|
||||
Spectate next
|
||||
==
|
||||
|
||||
Spectate previous
|
||||
==
|
||||
|
||||
##### old translations #####
|
||||
|
||||
Page %d of %d
|
||||
|
|
|
@ -657,5 +657,14 @@ no limit
|
|||
|
||||
##### needs translation #####
|
||||
|
||||
Play background music
|
||||
==
|
||||
|
||||
Spectate next
|
||||
==
|
||||
|
||||
Spectate previous
|
||||
==
|
||||
|
||||
##### old translations #####
|
||||
|
||||
|
|
673
data/languages/danish.txt
Normal file
673
data/languages/danish.txt
Normal file
|
@ -0,0 +1,673 @@
|
|||
|
||||
##### translated strings #####
|
||||
|
||||
%d Bytes
|
||||
== %d Bytes
|
||||
|
||||
%d of %d servers, %d players
|
||||
== %d af %d servere, %d spillere
|
||||
|
||||
%d%% loaded
|
||||
== %d%% indlæst
|
||||
|
||||
%ds left
|
||||
== %d sekunder tilbage
|
||||
|
||||
%i minute left
|
||||
== %i minut tilbage
|
||||
|
||||
%i minutes left
|
||||
== %i minutter tilbage
|
||||
|
||||
%i second left
|
||||
== %i sekund tilbage
|
||||
|
||||
%i seconds left
|
||||
== %i sekunder tilbage
|
||||
|
||||
%s wins!
|
||||
== %s vinder!
|
||||
|
||||
-Page %d-
|
||||
== -Side %d-
|
||||
|
||||
Abort
|
||||
== Afbryd
|
||||
|
||||
Add
|
||||
== Tilføj
|
||||
|
||||
Add Friend
|
||||
== Tilføj ven
|
||||
|
||||
Address
|
||||
== Adresse
|
||||
|
||||
All
|
||||
== Alle
|
||||
|
||||
Alpha
|
||||
== Alpha
|
||||
|
||||
Always show name plates
|
||||
== Vis altid navneskilte
|
||||
|
||||
Are you sure that you want to delete the demo?
|
||||
== Er du sikker på at du vil slette denne demo?
|
||||
|
||||
Are you sure that you want to quit?
|
||||
== Er du sikker på at du vil afslutte?
|
||||
|
||||
Are you sure that you want to remove the player from your friends list?
|
||||
== Er du sikker på at du vil fjerne denne spiller fra din venneliste?
|
||||
|
||||
As this is the first time you launch the game, please enter your nick name below. It's recommended that you check the settings to adjust them to your liking before joining a server.
|
||||
== Siden dette er første gang du starter spillet, så vær så venlig at skrive dit navn nedenunder. Det anbefales at du kigger på indstillingerne så du kan tilpasse dem inden du kobler dig på en server.
|
||||
|
||||
Automatically record demos
|
||||
== Optag automatisk demoer
|
||||
|
||||
Automatically take game over screenshot
|
||||
== Tag automatisk et game over screenshot
|
||||
|
||||
Blue team
|
||||
== Blå hold
|
||||
|
||||
Blue team wins!
|
||||
== Blåt hold vinder!
|
||||
|
||||
Body
|
||||
== Krop
|
||||
|
||||
Call vote
|
||||
== Lav afstemning
|
||||
|
||||
Change settings
|
||||
== Ændre indstillinger
|
||||
|
||||
Chat
|
||||
== Chat
|
||||
|
||||
Clan
|
||||
== Klan
|
||||
|
||||
Client
|
||||
== Klient
|
||||
|
||||
Close
|
||||
== Luk
|
||||
|
||||
Compatible version
|
||||
== Kompatibel version
|
||||
|
||||
Connect
|
||||
== Tilslut
|
||||
|
||||
Connecting to
|
||||
== Forbinder til
|
||||
|
||||
Connection Problems...
|
||||
== Forbindelsesproblemer...
|
||||
|
||||
Console
|
||||
== Konsol
|
||||
|
||||
Controls
|
||||
== Taster
|
||||
|
||||
Count players only
|
||||
== Tæl kun spillere
|
||||
|
||||
Country
|
||||
== Land
|
||||
|
||||
Crc:
|
||||
== Crc:
|
||||
|
||||
Created:
|
||||
== Lavet:
|
||||
|
||||
Current
|
||||
== Nuværende
|
||||
|
||||
Current version: %s
|
||||
== Nuværende version: %s
|
||||
|
||||
Custom colors
|
||||
== Brugerdefinerede farver
|
||||
|
||||
Delete
|
||||
== Slet
|
||||
|
||||
Delete demo
|
||||
== Slet demo
|
||||
|
||||
Demo details
|
||||
== Demoinformation
|
||||
|
||||
Demos
|
||||
== Demoer
|
||||
|
||||
Disconnect
|
||||
== Frakoble
|
||||
|
||||
Disconnected
|
||||
== Frakoblet
|
||||
|
||||
Display Modes
|
||||
== Skærmopløsning
|
||||
|
||||
Downloading map
|
||||
== Downloader bane
|
||||
|
||||
Draw!
|
||||
== Uafgjort!
|
||||
|
||||
Dynamic Camera
|
||||
== Dynamisk kamera
|
||||
|
||||
Emoticon
|
||||
== Humørikoner
|
||||
|
||||
Enter
|
||||
== Fortsæt
|
||||
|
||||
Error
|
||||
== Fejl
|
||||
|
||||
Error loading demo
|
||||
== Kunne ikke ikke indlæse demoen
|
||||
|
||||
FSAA samples
|
||||
== FSAA samples
|
||||
|
||||
Favorite
|
||||
== Favorit
|
||||
|
||||
Favorites
|
||||
== Favoritter
|
||||
|
||||
Feet
|
||||
== Fødder
|
||||
|
||||
Filter
|
||||
== Filter
|
||||
|
||||
Fire
|
||||
== Skyd
|
||||
|
||||
Folder
|
||||
== Mappe
|
||||
|
||||
Force vote
|
||||
== Tving afstemning
|
||||
|
||||
Free-View
|
||||
== Free-View
|
||||
|
||||
Friends
|
||||
== Venner
|
||||
|
||||
Fullscreen
|
||||
== Fuldskærm
|
||||
|
||||
Game
|
||||
== Spil
|
||||
|
||||
Game info
|
||||
== Spil info
|
||||
|
||||
Game over
|
||||
== Game over
|
||||
|
||||
Game type
|
||||
== Spiltype
|
||||
|
||||
Game types:
|
||||
== Spiltyper:
|
||||
|
||||
General
|
||||
== Generelt
|
||||
|
||||
Graphics
|
||||
== Grafik
|
||||
|
||||
Grenade
|
||||
== Granatkaster
|
||||
|
||||
Hammer
|
||||
== Hammer
|
||||
|
||||
Has people playing
|
||||
== Har folk som spiller
|
||||
|
||||
High Detail
|
||||
== Extra detaljer
|
||||
|
||||
Hook
|
||||
== Krog
|
||||
|
||||
Host address
|
||||
== Værtsadresse
|
||||
|
||||
Hue
|
||||
== Farve
|
||||
|
||||
Info
|
||||
== Info
|
||||
|
||||
Internet
|
||||
== Internet
|
||||
|
||||
Invalid Demo
|
||||
== Ugyldig demo
|
||||
|
||||
Join blue
|
||||
== Spil for blå
|
||||
|
||||
Join game
|
||||
== Start spil
|
||||
|
||||
Join red
|
||||
== Spil for rød
|
||||
|
||||
Jump
|
||||
== Hop
|
||||
|
||||
Kick player
|
||||
== Udsmid spiller
|
||||
|
||||
LAN
|
||||
== LAN
|
||||
|
||||
Language
|
||||
== Sprog
|
||||
|
||||
Length:
|
||||
== Længde
|
||||
|
||||
Lht.
|
||||
== Lys
|
||||
|
||||
Loading
|
||||
== Indlæser
|
||||
|
||||
MOTD
|
||||
== MOTD
|
||||
|
||||
Map
|
||||
== Kort
|
||||
|
||||
Map:
|
||||
== Bane
|
||||
|
||||
Max Screenshots
|
||||
== Max antal screenshots
|
||||
|
||||
Max demos
|
||||
== Max antal demoer
|
||||
|
||||
Maximum ping:
|
||||
== Højeste ping:
|
||||
|
||||
Miscellaneous
|
||||
== Diverse
|
||||
|
||||
Mouse sens.
|
||||
== Musfølsomhed
|
||||
|
||||
Move left
|
||||
== Gå til venstre
|
||||
|
||||
Move player to spectators
|
||||
== Flyt spilleren til tilskuerne
|
||||
|
||||
Move right
|
||||
== Gå til højre
|
||||
|
||||
Movement
|
||||
== Bevægelse
|
||||
|
||||
Mute when not active
|
||||
== Ingen lyd når du ikke er aktiv
|
||||
|
||||
Name
|
||||
== Navn
|
||||
|
||||
Name plates size
|
||||
== Størrelse på navneskilte
|
||||
|
||||
Netversion:
|
||||
== Netversion:
|
||||
|
||||
New name:
|
||||
== Nyt navn:
|
||||
|
||||
News
|
||||
== Nyheder
|
||||
|
||||
Next weapon
|
||||
== Næste våben
|
||||
|
||||
Nickname
|
||||
== Navn
|
||||
|
||||
No
|
||||
== Nej
|
||||
|
||||
No password
|
||||
== Ingen adgangskode
|
||||
|
||||
No servers found
|
||||
== Ingen servere fundet
|
||||
|
||||
No servers match your filter criteria
|
||||
== Ingen servere matcher din filterkriterier
|
||||
|
||||
Ok
|
||||
== Ok
|
||||
|
||||
Open
|
||||
== Åben
|
||||
|
||||
Parent Folder
|
||||
== Overmappe
|
||||
|
||||
Password
|
||||
== Adgangskode
|
||||
|
||||
Password incorrect
|
||||
== Forkert adgangskode
|
||||
|
||||
Ping
|
||||
== Ping
|
||||
|
||||
Pistol
|
||||
== Pistol
|
||||
|
||||
Play
|
||||
== Spil
|
||||
|
||||
Player
|
||||
== Spiller
|
||||
|
||||
Player options
|
||||
== Spillermuligheder
|
||||
|
||||
Players
|
||||
== Spillere
|
||||
|
||||
Please balance teams!
|
||||
== Venligst balancerer hold!
|
||||
|
||||
Prev. weapon
|
||||
== Foregående våben
|
||||
|
||||
Quality Textures
|
||||
== Kvalitetsteksturer
|
||||
|
||||
Quick search:
|
||||
== Hurtig søg:
|
||||
|
||||
Quit
|
||||
== Afslut
|
||||
|
||||
Quit anyway?
|
||||
== Afslut alligevel?
|
||||
|
||||
REC %3d:%02d
|
||||
== REC %3d:%02d
|
||||
|
||||
Reason:
|
||||
== Grund:
|
||||
|
||||
Record demo
|
||||
== Optag demo
|
||||
|
||||
Red team
|
||||
== Rødt hold
|
||||
|
||||
Red team wins!
|
||||
== Rødt hold vinder!
|
||||
|
||||
Refresh
|
||||
== Opdater
|
||||
|
||||
Refreshing master servers
|
||||
== Opdaterer masterservere
|
||||
|
||||
Remote console
|
||||
== Serverkonsol
|
||||
|
||||
Remove
|
||||
== Fjern
|
||||
|
||||
Remove friend
|
||||
== Fjern ven
|
||||
|
||||
Rename
|
||||
== Omdøb navn
|
||||
|
||||
Rename demo
|
||||
== Omdøb navn på demoen
|
||||
|
||||
Reset filter
|
||||
== Nulstil filter
|
||||
|
||||
Reset to defaults
|
||||
== Sæt til standard
|
||||
|
||||
Rifle
|
||||
== Laser
|
||||
|
||||
Round
|
||||
== Runde
|
||||
|
||||
Sample rate
|
||||
== Sample frekvens
|
||||
|
||||
Sat.
|
||||
== Mætning
|
||||
|
||||
Score
|
||||
== Score
|
||||
|
||||
Score board
|
||||
== Resultatliste
|
||||
|
||||
Score limit
|
||||
== Score grænse
|
||||
|
||||
Scoreboard
|
||||
== Resultatliste
|
||||
|
||||
Screenshot
|
||||
== Screenshot
|
||||
|
||||
Server address:
|
||||
== Serveradresse
|
||||
|
||||
Server details
|
||||
== Serverdetaljer
|
||||
|
||||
Server filter
|
||||
== Serverfilter
|
||||
|
||||
Server info
|
||||
== Serverinfo
|
||||
|
||||
Server not full
|
||||
== Ikke fuld server
|
||||
|
||||
Settings
|
||||
== Indstillinger
|
||||
|
||||
Shotgun
|
||||
== Haglgevær
|
||||
|
||||
Show chat
|
||||
== Vis chat
|
||||
|
||||
Show friends
|
||||
== Vis venner
|
||||
|
||||
Show ingame HUD
|
||||
== Vis HUD i spillet
|
||||
|
||||
Show name plates
|
||||
== Vis navneskilte
|
||||
|
||||
Show only supported
|
||||
== Vis kun understøttede
|
||||
|
||||
Size:
|
||||
== Størrelse:
|
||||
|
||||
Skins
|
||||
== Udseende
|
||||
|
||||
Sound
|
||||
== Lyd
|
||||
|
||||
Sound error
|
||||
== Lyd fejl
|
||||
|
||||
Sound volume
|
||||
== Lydstyrke
|
||||
|
||||
Spectate
|
||||
== Kig på
|
||||
|
||||
Spectator mode
|
||||
== Tilskuer mode
|
||||
|
||||
Spectators
|
||||
== Tilskuer
|
||||
|
||||
Standard gametype
|
||||
== Standard spilletype
|
||||
|
||||
Standard map
|
||||
== Standard
|
||||
|
||||
Stop record
|
||||
== Stop optagelse
|
||||
|
||||
Sudden Death
|
||||
== Sudden Death
|
||||
|
||||
Switch weapon on pickup
|
||||
== Byt våben ved anskafning
|
||||
|
||||
Team
|
||||
== Hold
|
||||
|
||||
Team chat
|
||||
== Holdchat
|
||||
|
||||
Teeworlds %s is out! Download it at www.teeworlds.com!
|
||||
== Teeworld %s er ude nu! Download den på www.teeworlds.com!
|
||||
|
||||
Texture Compression
|
||||
== Teksturkompression
|
||||
|
||||
The audio device couldn't be initialised.
|
||||
== Lydenheden kunne ikke startes
|
||||
|
||||
The server is running a non-standard tuning on a pure game type.
|
||||
== Denne server kører på en ikke-standard tuning på en ren spilletype.
|
||||
|
||||
There's an unsaved map in the editor, you might want to save it before you quit the game.
|
||||
== Der er en ikke-gemt bane i editoren, vil du gemme den før du afslutter?
|
||||
|
||||
Time limit
|
||||
== Tidsbegrænsning
|
||||
|
||||
Time limit: %d min
|
||||
== Tidsbegrænsning: %d min
|
||||
|
||||
Try again
|
||||
== Forsøg igen
|
||||
|
||||
Type
|
||||
== Type
|
||||
|
||||
Type:
|
||||
== Type:
|
||||
|
||||
UI Color
|
||||
== Brugergrænsefladefarve
|
||||
|
||||
Unable to delete the demo
|
||||
== Kunne ikke slette demoen
|
||||
|
||||
Unable to rename the demo
|
||||
== Kunne omdøbe demoen
|
||||
|
||||
Use sounds
|
||||
== Anvend lydeffekter
|
||||
|
||||
Use team colors for name plates
|
||||
== Anvend holdfarver til navneskilte
|
||||
|
||||
V-Sync
|
||||
== V-Sync
|
||||
|
||||
Version
|
||||
== Version
|
||||
|
||||
Version:
|
||||
== Version:
|
||||
|
||||
Vote command:
|
||||
== Afstemningsordre:
|
||||
|
||||
Vote description:
|
||||
== Afstemningsbeskrivelse:
|
||||
|
||||
Vote no
|
||||
== Stem nej
|
||||
|
||||
Vote yes
|
||||
== Stem ja
|
||||
|
||||
Voting
|
||||
== Afstemning
|
||||
|
||||
Warmup
|
||||
== Opvarmning
|
||||
|
||||
Weapon
|
||||
== Våben
|
||||
|
||||
Welcome to Teeworlds
|
||||
== Velkommen til Teeworlds
|
||||
|
||||
Yes
|
||||
== Ja
|
||||
|
||||
You must restart the game for all settings to take effect.
|
||||
== Du skal genstarte spillet før alle indstillingerne virker.
|
||||
|
||||
Your skin
|
||||
== Dit udseende
|
||||
|
||||
no limit
|
||||
== Ingen grænse
|
||||
|
||||
##### needs translation #####
|
||||
|
||||
Play background music
|
||||
==
|
||||
|
||||
Spectate next
|
||||
==
|
||||
|
||||
Spectate previous
|
||||
==
|
||||
|
||||
##### old translations #####
|
||||
|
||||
##### translated strings #####
|
||||
==
|
||||
|
|
@ -657,5 +657,14 @@ no limit
|
|||
|
||||
##### needs translation #####
|
||||
|
||||
Play background music
|
||||
==
|
||||
|
||||
Spectate next
|
||||
==
|
||||
|
||||
Spectate previous
|
||||
==
|
||||
|
||||
##### old translations #####
|
||||
|
||||
|
|
|
@ -657,5 +657,14 @@ no limit
|
|||
|
||||
##### needs translation #####
|
||||
|
||||
Play background music
|
||||
==
|
||||
|
||||
Spectate next
|
||||
==
|
||||
|
||||
Spectate previous
|
||||
==
|
||||
|
||||
##### old translations #####
|
||||
|
||||
|
|
|
@ -657,5 +657,14 @@ no limit
|
|||
|
||||
##### needs translation #####
|
||||
|
||||
Play background music
|
||||
==
|
||||
|
||||
Spectate next
|
||||
==
|
||||
|
||||
Spectate previous
|
||||
==
|
||||
|
||||
##### old translations #####
|
||||
|
||||
|
|
|
@ -657,5 +657,14 @@ no limit
|
|||
|
||||
##### needs translation #####
|
||||
|
||||
Play background music
|
||||
==
|
||||
|
||||
Spectate next
|
||||
==
|
||||
|
||||
Spectate previous
|
||||
==
|
||||
|
||||
##### old translations #####
|
||||
|
||||
|
|
|
@ -10,6 +10,9 @@ bulgarian
|
|||
czech
|
||||
== Česky
|
||||
|
||||
danish
|
||||
== Dansk
|
||||
|
||||
dutch
|
||||
== Nederlands
|
||||
|
||||
|
|
|
@ -588,6 +588,9 @@ Netversion:
|
|||
New name:
|
||||
==
|
||||
|
||||
Play background music
|
||||
==
|
||||
|
||||
Player options
|
||||
==
|
||||
|
||||
|
@ -627,6 +630,12 @@ Size:
|
|||
Sound error
|
||||
==
|
||||
|
||||
Spectate next
|
||||
==
|
||||
|
||||
Spectate previous
|
||||
==
|
||||
|
||||
Spectator mode
|
||||
==
|
||||
|
||||
|
|
|
@ -657,5 +657,14 @@ no limit
|
|||
|
||||
##### needs translation #####
|
||||
|
||||
Play background music
|
||||
==
|
||||
|
||||
Spectate next
|
||||
==
|
||||
|
||||
Spectate previous
|
||||
==
|
||||
|
||||
##### old translations #####
|
||||
|
||||
|
|
|
@ -573,6 +573,9 @@ New name:
|
|||
Parent Folder
|
||||
==
|
||||
|
||||
Play background music
|
||||
==
|
||||
|
||||
Player options
|
||||
==
|
||||
|
||||
|
@ -618,6 +621,12 @@ Size:
|
|||
Sound error
|
||||
==
|
||||
|
||||
Spectate next
|
||||
==
|
||||
|
||||
Spectate previous
|
||||
==
|
||||
|
||||
Spectator mode
|
||||
==
|
||||
|
||||
|
|
|
@ -657,5 +657,14 @@ no limit
|
|||
As this is the first time you launch the game, please enter your nick name below. It's recommended that you check the settings to adjust them to your liking before joining a server.
|
||||
==
|
||||
|
||||
Play background music
|
||||
==
|
||||
|
||||
Spectate next
|
||||
==
|
||||
|
||||
Spectate previous
|
||||
==
|
||||
|
||||
##### old translations #####
|
||||
|
||||
|
|
|
@ -657,5 +657,14 @@ no limit
|
|||
|
||||
##### needs translation #####
|
||||
|
||||
Play background music
|
||||
==
|
||||
|
||||
Spectate next
|
||||
==
|
||||
|
||||
Spectate previous
|
||||
==
|
||||
|
||||
##### old translations #####
|
||||
|
||||
|
|
|
@ -657,5 +657,14 @@ no limit
|
|||
|
||||
##### needs translation #####
|
||||
|
||||
Play background music
|
||||
==
|
||||
|
||||
Spectate next
|
||||
==
|
||||
|
||||
Spectate previous
|
||||
==
|
||||
|
||||
##### old translations #####
|
||||
|
||||
|
|
|
@ -573,6 +573,9 @@ Open
|
|||
Parent Folder
|
||||
==
|
||||
|
||||
Play background music
|
||||
==
|
||||
|
||||
Player options
|
||||
==
|
||||
|
||||
|
@ -618,6 +621,12 @@ Size:
|
|||
Sound error
|
||||
==
|
||||
|
||||
Spectate next
|
||||
==
|
||||
|
||||
Spectate previous
|
||||
==
|
||||
|
||||
Spectator mode
|
||||
==
|
||||
|
||||
|
|
|
@ -657,5 +657,14 @@ no limit
|
|||
|
||||
##### needs translation #####
|
||||
|
||||
Play background music
|
||||
==
|
||||
|
||||
Spectate next
|
||||
==
|
||||
|
||||
Spectate previous
|
||||
==
|
||||
|
||||
##### old translations #####
|
||||
|
||||
|
|
|
@ -657,6 +657,15 @@ no limit
|
|||
|
||||
##### needs translation #####
|
||||
|
||||
Play background music
|
||||
==
|
||||
|
||||
Spectate next
|
||||
==
|
||||
|
||||
Spectate previous
|
||||
==
|
||||
|
||||
##### old translations #####
|
||||
|
||||
Page %d of %d
|
||||
|
|
|
@ -657,5 +657,14 @@ no limit
|
|||
|
||||
##### needs translation #####
|
||||
|
||||
Play background music
|
||||
==
|
||||
|
||||
Spectate next
|
||||
==
|
||||
|
||||
Spectate previous
|
||||
==
|
||||
|
||||
##### old translations #####
|
||||
|
||||
|
|
|
@ -585,6 +585,9 @@ New name:
|
|||
Parent Folder
|
||||
==
|
||||
|
||||
Play background music
|
||||
==
|
||||
|
||||
Player options
|
||||
==
|
||||
|
||||
|
@ -624,6 +627,12 @@ Size:
|
|||
Sound error
|
||||
==
|
||||
|
||||
Spectate next
|
||||
==
|
||||
|
||||
Spectate previous
|
||||
==
|
||||
|
||||
Spectator mode
|
||||
==
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@ def create_flags_table(names):
|
|||
i += 1
|
||||
lines += ["};"]
|
||||
return lines
|
||||
|
||||
|
||||
def EmitEnum(names, num):
|
||||
print("enum")
|
||||
print("{")
|
||||
|
@ -92,11 +92,11 @@ if gen_client_content_source or gen_server_content_source:
|
|||
|
||||
# NETWORK
|
||||
if gen_network_header:
|
||||
|
||||
|
||||
print("#ifndef GAME_GENERATED_PROTOCOL_H")
|
||||
print("#define GAME_GENERATED_PROTOCOL_H")
|
||||
print(network.RawHeader)
|
||||
|
||||
|
||||
for e in network.Enums:
|
||||
for l in create_enum_table(["%s_%s"%(e.name, v) for v in e.values], 'NUM_%sS'%e.name): print(l)
|
||||
print("")
|
||||
|
@ -104,17 +104,17 @@ if gen_network_header:
|
|||
for e in network.Flags:
|
||||
for l in create_flags_table(["%s_%s" % (e.name, v) for v in e.values]): print(l)
|
||||
print("")
|
||||
|
||||
|
||||
for l in create_enum_table(["NETOBJ_INVALID"]+[o.enum_name for o in network.Objects], "NUM_NETOBJTYPES"): print(l)
|
||||
print("")
|
||||
for l in create_enum_table(["NETMSG_INVALID"]+[o.enum_name for o in network.Messages], "NUM_NETMSGTYPES"): print(l)
|
||||
print("")
|
||||
|
||||
|
||||
for item in network.Objects + network.Messages:
|
||||
for line in item.emit_declaration():
|
||||
print(line)
|
||||
print("")
|
||||
|
||||
|
||||
EmitEnum(["SOUND_%s"%i.name.value.upper() for i in content.container.sounds.items], "NUM_SOUNDS")
|
||||
EmitEnum(["WEAPON_%s"%i.name.value.upper() for i in content.container.weapons.id.items], "NUM_WEAPONS")
|
||||
|
||||
|
@ -127,11 +127,11 @@ class CNetObjHandler
|
|||
char m_aMsgData[1024];
|
||||
int m_NumObjCorrections;
|
||||
int ClampInt(const char *pErrorMsg, int Value, int Min, int Max);
|
||||
|
||||
|
||||
static const char *ms_apObjNames[];
|
||||
static int ms_aObjSizes[];
|
||||
static const char *ms_apMsgNames[];
|
||||
|
||||
|
||||
public:
|
||||
CNetObjHandler();
|
||||
|
||||
|
@ -140,7 +140,7 @@ public:
|
|||
int GetObjSize(int Type);
|
||||
int NumObjCorrections();
|
||||
const char *CorrectedObjOn();
|
||||
|
||||
|
||||
const char *GetMsgName(int Type);
|
||||
void *SecureUnpackMsg(int Type, CUnpacker *pUnpacker);
|
||||
const char *FailedMsgOn();
|
||||
|
@ -149,16 +149,16 @@ public:
|
|||
""")
|
||||
|
||||
print("#endif // GAME_GENERATED_PROTOCOL_H")
|
||||
|
||||
|
||||
|
||||
if gen_network_source:
|
||||
# create names
|
||||
lines = []
|
||||
|
||||
|
||||
lines += ['#include <engine/shared/protocol.h>']
|
||||
lines += ['#include <engine/message.h>']
|
||||
lines += ['#include "protocol.h"']
|
||||
|
||||
|
||||
lines += ['CNetObjHandler::CNetObjHandler()']
|
||||
lines += ['{']
|
||||
lines += ['\tm_pMsgFailedOn = "";']
|
||||
|
@ -202,7 +202,7 @@ if gen_network_source:
|
|||
lines += ['\t""']
|
||||
lines += ['};']
|
||||
lines += ['']
|
||||
|
||||
|
||||
lines += ['const char *CNetObjHandler::GetObjName(int Type)']
|
||||
lines += ['{']
|
||||
lines += ['\tif(Type < 0 || Type >= NUM_NETOBJTYPES) return "(out of range)";']
|
||||
|
@ -216,16 +216,16 @@ if gen_network_source:
|
|||
lines += ['\treturn ms_aObjSizes[Type];']
|
||||
lines += ['};']
|
||||
lines += ['']
|
||||
|
||||
|
||||
|
||||
|
||||
lines += ['const char *CNetObjHandler::GetMsgName(int Type)']
|
||||
lines += ['{']
|
||||
lines += ['\tif(Type < 0 || Type >= NUM_NETMSGTYPES) return "(out of range)";']
|
||||
lines += ['\treturn ms_apMsgNames[Type];']
|
||||
lines += ['};']
|
||||
lines += ['']
|
||||
|
||||
|
||||
|
||||
|
||||
for l in lines:
|
||||
print(l)
|
||||
|
||||
|
@ -255,7 +255,7 @@ if gen_network_source:
|
|||
lines += ['{']
|
||||
lines += ['\tswitch(Type)']
|
||||
lines += ['\t{']
|
||||
|
||||
|
||||
for item in network.Objects:
|
||||
for line in item.emit_validate():
|
||||
lines += ["\t" + line]
|
||||
|
@ -264,9 +264,9 @@ if gen_network_source:
|
|||
lines += ['\treturn -1;']
|
||||
lines += ['};']
|
||||
lines += ['']
|
||||
|
||||
#int Validate(int Type, void *pData, int Size);
|
||||
|
||||
|
||||
#int Validate(int Type, void *pData, int Size);
|
||||
|
||||
if 0:
|
||||
for item in network.Messages:
|
||||
for line in item.emit_unpack():
|
||||
|
@ -281,20 +281,20 @@ if gen_network_source:
|
|||
lines += ['\tsecure_unpack_%s,' % msg.name]
|
||||
lines += ['\t0x0']
|
||||
lines += ['};']
|
||||
|
||||
|
||||
#
|
||||
lines += ['void *CNetObjHandler::SecureUnpackMsg(int Type, CUnpacker *pUnpacker)']
|
||||
lines += ['{']
|
||||
lines += ['\tm_pMsgFailedOn = 0;']
|
||||
lines += ['\tswitch(Type)']
|
||||
lines += ['\t{']
|
||||
|
||||
|
||||
|
||||
|
||||
for item in network.Messages:
|
||||
for line in item.emit_unpack():
|
||||
lines += ["\t" + line]
|
||||
lines += ['\t']
|
||||
|
||||
|
||||
lines += ['\tdefault:']
|
||||
lines += ['\t\tm_pMsgFailedOn = "(type out of range)";']
|
||||
lines += ['\t\tbreak;']
|
||||
|
@ -313,6 +313,6 @@ if gen_network_source:
|
|||
|
||||
for l in lines:
|
||||
print(l)
|
||||
|
||||
|
||||
if gen_client_content_header or gen_server_content_header:
|
||||
print("#endif")
|
||||
|
|
|
@ -22,7 +22,7 @@ class Image(Struct):
|
|||
self.name = String(name)
|
||||
self.filename = String(filename)
|
||||
self.id = Int(-1)
|
||||
|
||||
|
||||
class SpriteSet(Struct):
|
||||
def __init__(self, name="", image=None, gridx=0, gridy=0):
|
||||
Struct.__init__(self, "SPRITESET")
|
||||
|
@ -78,7 +78,7 @@ class WeaponSpec(Struct):
|
|||
self.sprite_proj = Pointer(Sprite, Sprite())
|
||||
self.sprite_muzzles = Array(Pointer(Sprite, Sprite()))
|
||||
self.visual_size = Int(96)
|
||||
|
||||
|
||||
self.firedelay = Int(500)
|
||||
self.maxammo = Int(10)
|
||||
self.ammoregentime = Int(0)
|
||||
|
@ -111,7 +111,7 @@ class Weapon_Gun(Struct):
|
|||
self.curvature = Float(1.25)
|
||||
self.speed = Float(2200)
|
||||
self.lifetime = Float(2.0)
|
||||
|
||||
|
||||
class Weapon_Shotgun(Struct):
|
||||
def __init__(self):
|
||||
Struct.__init__(self, "WEAPONSPEC_SHOTGUN")
|
||||
|
@ -119,7 +119,7 @@ class Weapon_Shotgun(Struct):
|
|||
self.curvature = Float(1.25)
|
||||
self.speed = Float(2200)
|
||||
self.speeddiff = Float(0.8)
|
||||
self.lifetime = Float(0.25)
|
||||
self.lifetime = Float(0.25)
|
||||
|
||||
class Weapon_Grenade(Struct):
|
||||
def __init__(self):
|
||||
|
@ -137,7 +137,7 @@ class Weapon_Rifle(Struct):
|
|||
self.bounce_delay = Int(150)
|
||||
self.bounce_num = Int(1)
|
||||
self.bounce_cost = Float(0)
|
||||
|
||||
|
||||
class Weapon_Ninja(Struct):
|
||||
def __init__(self):
|
||||
Struct.__init__(self, "WEAPONSPEC_NINJA")
|
||||
|
@ -190,7 +190,7 @@ container.sounds.Add(SoundSet("player_pain_long", FileList("audio/vo_teefault_pa
|
|||
|
||||
container.sounds.Add(SoundSet("body_land", FileList("audio/foley_land-%02d.wv", 4)))
|
||||
container.sounds.Add(SoundSet("player_airjump", FileList("audio/foley_dbljump-%02d.wv", 3)))
|
||||
container.sounds.Add(SoundSet("player_jump", FileList("audio/foley_foot_left-%02d.wv", 4) + FileList("audio/foley_foot_right-%02d.wv", 4)))
|
||||
container.sounds.Add(SoundSet("player_jump", FileList("audio/foley_foot_left-%02d.wv", 4) + FileList("audio/foley_foot_right-%02d.wv", 4)))
|
||||
container.sounds.Add(SoundSet("player_die", FileList("audio/foley_body_splat-%02d.wv", 3)))
|
||||
container.sounds.Add(SoundSet("player_spawn", FileList("audio/vo_teefault_spawn-%02d.wv", 7)))
|
||||
container.sounds.Add(SoundSet("player_skid", FileList("audio/sfx_skid-%02d.wv", 4)))
|
||||
|
@ -221,6 +221,8 @@ container.sounds.Add(SoundSet("ctf_grab_pl", ["audio/sfx_ctf_grab_pl.wv"]))
|
|||
container.sounds.Add(SoundSet("ctf_grab_en", ["audio/sfx_ctf_grab_en.wv"]))
|
||||
container.sounds.Add(SoundSet("ctf_capture", ["audio/sfx_ctf_cap_pl.wv"]))
|
||||
|
||||
container.sounds.Add(SoundSet("menu", ["audio/music_menu.wv"]))
|
||||
|
||||
image_null = Image("null", "")
|
||||
image_particles = Image("particles", "particles.png")
|
||||
image_game = Image("game", "game.png")
|
||||
|
@ -294,7 +296,7 @@ container.sprites.Add(Sprite("armor_empty", set_game, 23,2,2,2))
|
|||
container.sprites.Add(Sprite("star1", set_game, 15,0,2,2))
|
||||
container.sprites.Add(Sprite("star2", set_game, 17,0,2,2))
|
||||
container.sprites.Add(Sprite("star3", set_game, 19,0,2,2))
|
||||
|
||||
|
||||
container.sprites.Add(Sprite("part1", set_game, 6,0,1,1))
|
||||
container.sprites.Add(Sprite("part2", set_game, 6,1,1,1))
|
||||
container.sprites.Add(Sprite("part3", set_game, 7,0,1,1))
|
||||
|
@ -429,35 +431,35 @@ anim.body.frames.Add(AnimKeyframe(0.6, 0, 0, 0))
|
|||
anim.body.frames.Add(AnimKeyframe(0.8, 0,-1, 0))
|
||||
anim.body.frames.Add(AnimKeyframe(1.0, 0, 0, 0))
|
||||
|
||||
anim.back_foot.frames.Add(AnimKeyframe(0.0, 8, 0, 0))
|
||||
anim.back_foot.frames.Add(AnimKeyframe(0.0, 8, 0, 0))
|
||||
anim.back_foot.frames.Add(AnimKeyframe(0.2, -8, 0, 0))
|
||||
anim.back_foot.frames.Add(AnimKeyframe(0.4,-10,-4, 0.2))
|
||||
anim.back_foot.frames.Add(AnimKeyframe(0.6, -8,-8, 0.3))
|
||||
anim.back_foot.frames.Add(AnimKeyframe(0.8, 4,-4,-0.2))
|
||||
anim.back_foot.frames.Add(AnimKeyframe(1.0, 8, 0, 0))
|
||||
anim.back_foot.frames.Add(AnimKeyframe(0.8, 4,-4,-0.2))
|
||||
anim.back_foot.frames.Add(AnimKeyframe(1.0, 8, 0, 0))
|
||||
|
||||
anim.front_foot.frames.Add(AnimKeyframe(0.0,-10,-4, 0.2))
|
||||
anim.front_foot.frames.Add(AnimKeyframe(0.2, -8,-8, 0.3))
|
||||
anim.front_foot.frames.Add(AnimKeyframe(0.4, 4,-4,-0.2))
|
||||
anim.front_foot.frames.Add(AnimKeyframe(0.6, 8, 0, 0))
|
||||
anim.front_foot.frames.Add(AnimKeyframe(0.8, 8, 0, 0))
|
||||
anim.front_foot.frames.Add(AnimKeyframe(0.4, 4,-4,-0.2))
|
||||
anim.front_foot.frames.Add(AnimKeyframe(0.6, 8, 0, 0))
|
||||
anim.front_foot.frames.Add(AnimKeyframe(0.8, 8, 0, 0))
|
||||
anim.front_foot.frames.Add(AnimKeyframe(1.0,-10,-4, 0.2))
|
||||
container.animations.Add(anim)
|
||||
|
||||
anim = Animation("hammer_swing")
|
||||
anim.attach.frames.Add(AnimKeyframe(0.0, 0, 0, -0.10))
|
||||
anim.attach.frames.Add(AnimKeyframe(0.3, 0, 0, 0.25))
|
||||
anim.attach.frames.Add(AnimKeyframe(0.4, 0, 0, 0.30))
|
||||
anim.attach.frames.Add(AnimKeyframe(0.5, 0, 0, 0.25))
|
||||
anim.attach.frames.Add(AnimKeyframe(0.3, 0, 0, 0.25))
|
||||
anim.attach.frames.Add(AnimKeyframe(0.4, 0, 0, 0.30))
|
||||
anim.attach.frames.Add(AnimKeyframe(0.5, 0, 0, 0.25))
|
||||
anim.attach.frames.Add(AnimKeyframe(1.0, 0, 0, -0.10))
|
||||
container.animations.Add(anim)
|
||||
|
||||
|
||||
anim = Animation("ninja_swing")
|
||||
anim.attach.frames.Add(AnimKeyframe(0.00, 0, 0, -0.25))
|
||||
anim.attach.frames.Add(AnimKeyframe(0.10, 0, 0, -0.05))
|
||||
anim.attach.frames.Add(AnimKeyframe(0.15, 0, 0, 0.35))
|
||||
anim.attach.frames.Add(AnimKeyframe(0.42, 0, 0, 0.40))
|
||||
anim.attach.frames.Add(AnimKeyframe(0.50, 0, 0, 0.35))
|
||||
anim.attach.frames.Add(AnimKeyframe(0.15, 0, 0, 0.35))
|
||||
anim.attach.frames.Add(AnimKeyframe(0.42, 0, 0, 0.40))
|
||||
anim.attach.frames.Add(AnimKeyframe(0.50, 0, 0, 0.35))
|
||||
anim.attach.frames.Add(AnimKeyframe(1.00, 0, 0, -0.25))
|
||||
container.animations.Add(anim)
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@ def FixCasing(Str):
|
|||
else:
|
||||
NewStr += c.lower()
|
||||
return NewStr
|
||||
|
||||
|
||||
def FormatName(type, name):
|
||||
if "*" in type:
|
||||
return "m_p" + FixCasing(name)
|
||||
|
@ -34,12 +34,12 @@ class BaseType:
|
|||
self._type_name = type_name
|
||||
self._target_name = "INVALID"
|
||||
self._id = GetID() # this is used to remember what order the members have in structures etc
|
||||
|
||||
|
||||
def Identifyer(self): return "x"+str(self._id)
|
||||
def TargetName(self): return self._target_name
|
||||
def TypeName(self): return self._type_name
|
||||
def ID(self): return self._id;
|
||||
|
||||
|
||||
def EmitDeclaration(self, name):
|
||||
return ["%s %s;"%(self.TypeName(), FormatName(self.TypeName(), name))]
|
||||
def EmitPreDefinition(self, target_name):
|
||||
|
@ -52,7 +52,7 @@ class MemberType:
|
|||
def __init__(self, name, var):
|
||||
self.name = name
|
||||
self.var = var
|
||||
|
||||
|
||||
class Struct(BaseType):
|
||||
def __init__(self, type_name):
|
||||
BaseType.__init__(self, type_name)
|
||||
|
@ -71,7 +71,7 @@ class Struct(BaseType):
|
|||
print(v.name, v.var)
|
||||
sys.exit(-1)
|
||||
return m
|
||||
|
||||
|
||||
def EmitTypeDeclaration(self, name):
|
||||
lines = []
|
||||
lines += ["struct " + self.TypeName()]
|
||||
|
@ -93,7 +93,7 @@ class Struct(BaseType):
|
|||
lines += ["\t" + " ".join(member.var.EmitDefinition("")) + ","]
|
||||
lines += ["}"]
|
||||
return lines
|
||||
|
||||
|
||||
class Array(BaseType):
|
||||
def __init__(self, type):
|
||||
BaseType.__init__(self, type.TypeName())
|
||||
|
@ -114,7 +114,7 @@ class Array(BaseType):
|
|||
for item in self.items:
|
||||
lines += item.EmitPreDefinition("%s[%d]"%(self.Identifyer(), i))
|
||||
i += 1
|
||||
|
||||
|
||||
if len(self.items):
|
||||
lines += ["static %s %s[] = {"%(self.TypeName(), self.Identifyer())]
|
||||
for item in self.items:
|
||||
|
@ -123,7 +123,7 @@ class Array(BaseType):
|
|||
lines += ["};"]
|
||||
else:
|
||||
lines += ["static %s *%s = 0;"%(self.TypeName(), self.Identifyer())]
|
||||
|
||||
|
||||
return lines
|
||||
def EmitDefinition(self, name):
|
||||
return [str(len(self.items))+","+self.Identifyer()]
|
||||
|
@ -139,7 +139,7 @@ class Int(BaseType):
|
|||
def EmitDefinition(self, name):
|
||||
return ["%d"%self.value]
|
||||
#return ["%d /* %s */"%(self.value, self._target_name)]
|
||||
|
||||
|
||||
class Float(BaseType):
|
||||
def __init__(self, value):
|
||||
BaseType.__init__(self, "float")
|
||||
|
@ -149,7 +149,7 @@ class Float(BaseType):
|
|||
def EmitDefinition(self, name):
|
||||
return ["%f"%self.value]
|
||||
#return ["%d /* %s */"%(self.value, self._target_name)]
|
||||
|
||||
|
||||
class String(BaseType):
|
||||
def __init__(self, value):
|
||||
BaseType.__init__(self, "const char*")
|
||||
|
@ -158,7 +158,7 @@ class String(BaseType):
|
|||
self.value = value
|
||||
def EmitDefinition(self, name):
|
||||
return ['"'+self.value+'"']
|
||||
|
||||
|
||||
class Pointer(BaseType):
|
||||
def __init__(self, type, target):
|
||||
BaseType.__init__(self, "%s*"%type().TypeName())
|
||||
|
@ -227,7 +227,7 @@ class NetObject:
|
|||
lines += ["\treturn 0;"]
|
||||
lines += ["}"]
|
||||
return lines
|
||||
|
||||
|
||||
|
||||
class NetEvent(NetObject):
|
||||
def __init__(self, name, variables):
|
||||
|
@ -265,12 +265,12 @@ class NetMessage(NetObject):
|
|||
extra += ["\t\t"+line for line in v.emit_pack()]
|
||||
extra += ["\t\treturn pPacker->Error() != 0;"]
|
||||
extra += ["\t}"]
|
||||
|
||||
|
||||
|
||||
|
||||
lines = NetObject.emit_declaration(self)
|
||||
lines = lines[:-1] + extra + lines[-1:]
|
||||
return lines
|
||||
|
||||
|
||||
|
||||
class NetVariable:
|
||||
def __init__(self, name):
|
||||
|
|
|
@ -5,7 +5,7 @@ PlayerFlags = ["PLAYING", "IN_MENU", "CHATTING", "SCOREBOARD"]
|
|||
GameFlags = ["TEAMS", "FLAGS"]
|
||||
GameStateFlags = ["GAMEOVER", "SUDDENDEATH", "PAUSED"]
|
||||
|
||||
Emoticons = [str(x) for x in range(0,16)]
|
||||
Emoticons = ["OOP", "EXCLAMATION", "HEARTS", "DROP", "DOTDOT", "MUSIC", "SORRY", "GHOST", "SUSHI", "SPLATTEE", "DEVILTEE", "ZOMG", "ZZZ", "WTF", "EYES", "QUESTION"]
|
||||
|
||||
Powerups = ["HEALTH", "ARMOR", "WEAPON", "NINJA"]
|
||||
|
||||
|
@ -55,24 +55,24 @@ Objects = [
|
|||
NetIntAny("m_Direction"),
|
||||
NetIntAny("m_TargetX"),
|
||||
NetIntAny("m_TargetY"),
|
||||
|
||||
|
||||
NetIntAny("m_Jump"),
|
||||
NetIntAny("m_Fire"),
|
||||
NetIntAny("m_Hook"),
|
||||
|
||||
|
||||
NetIntRange("m_PlayerFlags", 0, 256),
|
||||
|
||||
|
||||
NetIntAny("m_WantedWeapon"),
|
||||
NetIntAny("m_NextWeapon"),
|
||||
NetIntAny("m_PrevWeapon"),
|
||||
]),
|
||||
|
||||
|
||||
NetObject("Projectile", [
|
||||
NetIntAny("m_X"),
|
||||
NetIntAny("m_Y"),
|
||||
NetIntAny("m_VelX"),
|
||||
NetIntAny("m_VelY"),
|
||||
|
||||
|
||||
NetIntRange("m_Type", 0, 'NUM_WEAPONS-1'),
|
||||
NetTick("m_StartTick"),
|
||||
]),
|
||||
|
@ -82,14 +82,14 @@ Objects = [
|
|||
NetIntAny("m_Y"),
|
||||
NetIntAny("m_FromX"),
|
||||
NetIntAny("m_FromY"),
|
||||
|
||||
|
||||
NetTick("m_StartTick"),
|
||||
]),
|
||||
|
||||
NetObject("Pickup", [
|
||||
NetIntAny("m_X"),
|
||||
NetIntAny("m_Y"),
|
||||
|
||||
|
||||
NetIntRange("m_Type", 0, 'max_int'),
|
||||
NetIntRange("m_Subtype", 0, 'max_int'),
|
||||
]),
|
||||
|
@ -97,7 +97,7 @@ Objects = [
|
|||
NetObject("Flag", [
|
||||
NetIntAny("m_X"),
|
||||
NetIntAny("m_Y"),
|
||||
|
||||
|
||||
NetIntRange("m_Team", 'TEAM_RED', 'TEAM_BLUE')
|
||||
]),
|
||||
|
||||
|
@ -106,10 +106,10 @@ Objects = [
|
|||
NetIntRange("m_GameStateFlags", 0, 256),
|
||||
NetTick("m_RoundStartTick"),
|
||||
NetIntRange("m_WarmupTimer", 0, 'max_int'),
|
||||
|
||||
|
||||
NetIntRange("m_ScoreLimit", 0, 'max_int'),
|
||||
NetIntRange("m_TimeLimit", 0, 'max_int'),
|
||||
|
||||
|
||||
NetIntRange("m_RoundNum", 0, 'max_int'),
|
||||
NetIntRange("m_RoundCurrent", 0, 'max_int'),
|
||||
]),
|
||||
|
@ -131,7 +131,7 @@ Objects = [
|
|||
|
||||
NetIntAny("m_Angle"),
|
||||
NetIntRange("m_Direction", -1, 1),
|
||||
|
||||
|
||||
NetIntRange("m_Jumped", 0, 3),
|
||||
NetIntRange("m_HookedPlayer", 0, 'MAX_CLIENTS-1'),
|
||||
NetIntRange("m_HookState", -1, 5),
|
||||
|
@ -152,7 +152,7 @@ Objects = [
|
|||
NetIntRange("m_Emote", 0, len(Emotes)),
|
||||
NetIntRange("m_AttackTick", 0, 'max_int'),
|
||||
]),
|
||||
|
||||
|
||||
NetObject("PlayerInfo", [
|
||||
NetIntRange("m_Local", 0, 1),
|
||||
NetIntRange("m_ClientID", 0, 'MAX_CLIENTS-1'),
|
||||
|
@ -177,7 +177,7 @@ Objects = [
|
|||
NetIntAny("m_Skin3"), NetIntAny("m_Skin4"), NetIntAny("m_Skin5"),
|
||||
|
||||
NetIntRange("m_UseCustomColor", 0, 1),
|
||||
|
||||
|
||||
NetIntAny("m_ColorBody"),
|
||||
NetIntAny("m_ColorFeet"),
|
||||
]),
|
||||
|
@ -187,23 +187,23 @@ Objects = [
|
|||
NetIntAny("m_X"),
|
||||
NetIntAny("m_Y"),
|
||||
]),
|
||||
|
||||
|
||||
## Events
|
||||
|
||||
|
||||
NetEvent("Common", [
|
||||
NetIntAny("m_X"),
|
||||
NetIntAny("m_Y"),
|
||||
]),
|
||||
|
||||
|
||||
|
||||
NetEvent("Explosion:Common", []),
|
||||
NetEvent("Spawn:Common", []),
|
||||
NetEvent("HammerHit:Common", []),
|
||||
|
||||
|
||||
NetEvent("Death:Common", [
|
||||
NetIntRange("m_ClientID", 0, 'MAX_CLIENTS-1'),
|
||||
]),
|
||||
|
||||
|
||||
NetEvent("SoundGlobal:Common", [
|
||||
NetIntRange("m_SoundID", 0, 'NUM_SOUNDS-1'),
|
||||
]),
|
||||
|
@ -233,7 +233,7 @@ Messages = [
|
|||
NetIntRange("m_ClientID", -1, 'MAX_CLIENTS-1'),
|
||||
NetString("m_pMessage"),
|
||||
]),
|
||||
|
||||
|
||||
NetMessage("Sv_KillMsg", [
|
||||
NetIntRange("m_Killer", 0, 'MAX_CLIENTS-1'),
|
||||
NetIntRange("m_Victim", 0, 'MAX_CLIENTS-1'),
|
||||
|
@ -244,7 +244,7 @@ Messages = [
|
|||
NetMessage("Sv_SoundGlobal", [
|
||||
NetIntRange("m_SoundID", 0, 'NUM_SOUNDS-1'),
|
||||
]),
|
||||
|
||||
|
||||
NetMessage("Sv_TuneParams", []),
|
||||
NetMessage("Sv_ExtraProjectile", []),
|
||||
NetMessage("Sv_ReadyToEnter", []),
|
||||
|
@ -260,7 +260,7 @@ Messages = [
|
|||
|
||||
NetMessage("Sv_VoteClearOptions", [
|
||||
]),
|
||||
|
||||
|
||||
NetMessage("Sv_VoteOptionListAdd", [
|
||||
NetIntRange("m_NumOptions", 1, 15),
|
||||
NetStringStrict("m_pDescription0"), NetStringStrict("m_pDescription1"), NetStringStrict("m_pDescription2"),
|
||||
|
@ -290,7 +290,7 @@ Messages = [
|
|||
NetIntRange("m_Pass", 0, 'MAX_CLIENTS'),
|
||||
NetIntRange("m_Total", 0, 'MAX_CLIENTS'),
|
||||
]),
|
||||
|
||||
|
||||
### Client messages
|
||||
NetMessage("Cl_Say", [
|
||||
NetBool("m_Team"),
|
||||
|
@ -304,7 +304,7 @@ Messages = [
|
|||
NetMessage("Cl_SetSpectatorMode", [
|
||||
NetIntRange("m_SpectatorID", 'SPEC_FREEVIEW', 'MAX_CLIENTS-1'),
|
||||
]),
|
||||
|
||||
|
||||
NetMessage("Cl_StartInfo", [
|
||||
NetStringStrict("m_pName"),
|
||||
NetStringStrict("m_pClan"),
|
||||
|
@ -313,7 +313,7 @@ Messages = [
|
|||
NetBool("m_UseCustomColor"),
|
||||
NetIntAny("m_ColorBody"),
|
||||
NetIntAny("m_ColorFeet"),
|
||||
]),
|
||||
]),
|
||||
|
||||
NetMessage("Cl_ChangeInfo", [
|
||||
NetStringStrict("m_pName"),
|
||||
|
@ -334,7 +334,7 @@ Messages = [
|
|||
NetMessage("Cl_Vote", [
|
||||
NetIntRange("m_Vote", -1, 1),
|
||||
]),
|
||||
|
||||
|
||||
NetMessage("Cl_CallVote", [
|
||||
NetStringStrict("m_Type"),
|
||||
NetStringStrict("m_Value"),
|
||||
|
|
35
scripts/check_header_guards.py
Normal file
35
scripts/check_header_guards.py
Normal file
|
@ -0,0 +1,35 @@
|
|||
import os
|
||||
|
||||
|
||||
PATH = "../src/"
|
||||
|
||||
|
||||
def check_file(filename):
|
||||
file = open(filename)
|
||||
while 1:
|
||||
line = file.readline()
|
||||
if len(line) == 0:
|
||||
break
|
||||
if line[0] == "/" or line[0] == "*" or line[0] == "\r" or line[0] == "\n" or line[0] == "\t":
|
||||
continue
|
||||
if line[:7] == "#ifndef":
|
||||
hg = "#ifndef " + ("_".join(filename.split(PATH)[1].split("/"))[:-2]).upper() + "_H"
|
||||
if line[:-1] != hg:
|
||||
print "Wrong header guard in " + filename
|
||||
else:
|
||||
print "Missing header guard in " + filename
|
||||
break
|
||||
file.close()
|
||||
|
||||
|
||||
|
||||
def check_dir(dir):
|
||||
list = os.listdir(dir)
|
||||
for file in list:
|
||||
if os.path.isdir(dir+file):
|
||||
if file != "external" and file != "generated":
|
||||
check_dir(dir+file+"/")
|
||||
elif file[-2:] == ".h" and file != "keynames.h":
|
||||
check_file(dir+file)
|
||||
|
||||
check_dir(PATH)
|
|
@ -29,5 +29,8 @@ for filename in sys.argv[1:]:
|
|||
f += cstrip([l.strip() for l in open(filename, "rb")])
|
||||
|
||||
hash = hashlib.md5(f).hexdigest().lower()[16:]
|
||||
#TODO 0.7: improve nethash creation
|
||||
if hash == "6e28a475de43adfd":
|
||||
hash = "626fce9a778df4d4"
|
||||
print('#define GAME_NETVERSION_HASH "%s"' % hash)
|
||||
print('#define GIT_SHORTREV_HASH "%s"' % os.popen('git rev-parse HEAD').readline(8))
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
|
||||
/* If you are missing that file, acquire a complete release at teeworlds.com. */
|
||||
#ifndef BASELIB_FILE_CONFIG_H
|
||||
#define BASELIB_FILE_CONFIG_H
|
||||
#ifndef BASE_DETECT_H
|
||||
#define BASE_DETECT_H
|
||||
|
||||
/*
|
||||
this file detected the family, platform and architecture
|
||||
to compile for.
|
||||
this file detected the family, platform and architecture
|
||||
to compile for.
|
||||
*/
|
||||
|
||||
/* platforms */
|
||||
|
|
|
@ -21,20 +21,20 @@
|
|||
#include <sys/socket.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <errno.h>
|
||||
#include <netdb.h>
|
||||
#include <netdb.h>
|
||||
#include <netinet/in.h>
|
||||
#include <fcntl.h>
|
||||
#include <pthread.h>
|
||||
#include <arpa/inet.h>
|
||||
|
||||
#include <dirent.h>
|
||||
|
||||
|
||||
#if defined(CONF_PLATFORM_MACOSX)
|
||||
#include <Carbon/Carbon.h>
|
||||
#endif
|
||||
|
||||
|
||||
#elif defined(CONF_FAMILY_WINDOWS)
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#define _WIN32_WINNT 0x0501 /* required for mingw to get getaddrinfo to work */
|
||||
#include <windows.h>
|
||||
#include <winsock2.h>
|
||||
|
@ -186,7 +186,7 @@ void *mem_alloc_debug(const char *filename, int line, unsigned size, unsigned al
|
|||
memory_stats.allocated += header->size;
|
||||
memory_stats.total_allocations++;
|
||||
memory_stats.active_allocations++;
|
||||
|
||||
|
||||
tail->guard = MEM_GUARD_VAL;
|
||||
|
||||
header->prev = (MEMHEADER *)0;
|
||||
|
@ -194,7 +194,7 @@ void *mem_alloc_debug(const char *filename, int line, unsigned size, unsigned al
|
|||
if(first)
|
||||
first->prev = header;
|
||||
first = header;
|
||||
|
||||
|
||||
/*dbg_msg("mem", "++ %p", header+1); */
|
||||
return header+1;
|
||||
}
|
||||
|
@ -205,20 +205,20 @@ void mem_free(void *p)
|
|||
{
|
||||
MEMHEADER *header = (MEMHEADER *)p - 1;
|
||||
MEMTAIL *tail = (MEMTAIL *)(((char*)(header+1))+header->size);
|
||||
|
||||
|
||||
if(tail->guard != MEM_GUARD_VAL)
|
||||
dbg_msg("mem", "!! %p", p);
|
||||
/* dbg_msg("mem", "-- %p", p); */
|
||||
memory_stats.allocated -= header->size;
|
||||
memory_stats.active_allocations--;
|
||||
|
||||
|
||||
if(header->prev)
|
||||
header->prev->next = header->next;
|
||||
else
|
||||
first = header->next;
|
||||
if(header->next)
|
||||
header->next->prev = header->prev;
|
||||
|
||||
|
||||
free(header);
|
||||
}
|
||||
}
|
||||
|
@ -229,7 +229,7 @@ void mem_debug_dump(IOHANDLE file)
|
|||
MEMHEADER *header = first;
|
||||
if(!file)
|
||||
file = io_open("memory.txt", IOFLAG_WRITE);
|
||||
|
||||
|
||||
if(file)
|
||||
{
|
||||
while(header)
|
||||
|
@ -238,7 +238,7 @@ void mem_debug_dump(IOHANDLE file)
|
|||
io_write(file, buf, strlen(buf));
|
||||
header = header->next;
|
||||
}
|
||||
|
||||
|
||||
io_close(file);
|
||||
}
|
||||
}
|
||||
|
@ -285,7 +285,7 @@ IOHANDLE io_open(const char *filename, int flags)
|
|||
WIN32_FIND_DATA finddata;
|
||||
HANDLE handle;
|
||||
int length;
|
||||
|
||||
|
||||
length = str_length(filename);
|
||||
if(!filename || !length || filename[length-1] == '\\')
|
||||
return 0x0;
|
||||
|
@ -640,9 +640,9 @@ int net_host_lookup(const char *hostname, NETADDR *addr, int types)
|
|||
/*
|
||||
dbg_msg("host lookup", "host='%s' port=%d %d", host, port, types);
|
||||
*/
|
||||
|
||||
|
||||
mem_zero(&hints, sizeof(hints));
|
||||
|
||||
|
||||
hints.ai_family = AF_UNSPEC;
|
||||
|
||||
if(types == NETTYPE_IPV4)
|
||||
|
@ -665,8 +665,8 @@ static int parse_int(int *out, const char **str)
|
|||
int i = 0;
|
||||
*out = 0;
|
||||
if(**str < '0' || **str > '9')
|
||||
return -1;
|
||||
|
||||
return -1;
|
||||
|
||||
i = **str - '0';
|
||||
(*str)++;
|
||||
|
||||
|
@ -675,9 +675,9 @@ static int parse_int(int *out, const char **str)
|
|||
if(**str < '0' || **str > '9')
|
||||
{
|
||||
*out = i;
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
i = (i*10) + (**str - '0');
|
||||
(*str)++;
|
||||
}
|
||||
|
@ -714,7 +714,7 @@ int net_addr_from_str(NETADDR *addr, const char *string)
|
|||
{
|
||||
const char *str = string;
|
||||
mem_zero(addr, sizeof(NETADDR));
|
||||
|
||||
|
||||
if(str[0] == '[')
|
||||
{
|
||||
/* ipv6 */
|
||||
|
@ -770,10 +770,10 @@ int net_addr_from_str(NETADDR *addr, const char *string)
|
|||
str++;
|
||||
if(parse_uint16(&addr->port, &str)) return -1;
|
||||
}
|
||||
|
||||
|
||||
addr->type = NETTYPE_IPV4;
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -835,7 +835,7 @@ static int priv_net_create_socket(int domain, int type, struct sockaddr *addr, i
|
|||
priv_net_close_socket(sock);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
/* set non-blocking */
|
||||
#if defined(CONF_FAMILY_WINDOWS)
|
||||
ioctlsocket(sock, FIONBIO, &mode);
|
||||
|
@ -845,7 +845,7 @@ static int priv_net_create_socket(int domain, int type, struct sockaddr *addr, i
|
|||
|
||||
/* set boardcast */
|
||||
setsockopt(sock, SOL_SOCKET, SO_BROADCAST, (const char*)&broadcast, sizeof(broadcast));
|
||||
|
||||
|
||||
/* return the newly created socket */
|
||||
return sock;
|
||||
}
|
||||
|
@ -947,7 +947,7 @@ int net_udp_send(NETSOCKET sock, const NETADDR *addr, const void *data, int size
|
|||
{
|
||||
char addrstr[256];
|
||||
net_addr_str(addr, addrstr, sizeof(addrstr));
|
||||
|
||||
|
||||
dbg_msg("net", "sendto error (%d '%s')", errno, strerror(errno));
|
||||
dbg_msg("net", "\tsock = %d %x", sock, sock);
|
||||
dbg_msg("net", "\tsize = %d %x", size, size);
|
||||
|
@ -1015,8 +1015,8 @@ NETSOCKET net_tcp_create(const NETADDR *a)
|
|||
bind(sock.ipv4sock, (struct sockaddr *)&addr, sizeof(addr));
|
||||
}
|
||||
|
||||
/* return */
|
||||
return sock;
|
||||
/* return */
|
||||
return sock;
|
||||
}
|
||||
|
||||
int net_tcp_set_non_blocking(NETSOCKET sock)
|
||||
|
@ -1132,7 +1132,7 @@ int net_tcp_connect_non_blocking(NETSOCKET sock, const NETADDR *a)
|
|||
/*
|
||||
netaddr_to_sockaddr(a, &addr);
|
||||
net_tcp_set_non_blocking(sock);
|
||||
res = connect(sock, &addr, sizeof(addr));
|
||||
res = connect(sock, &addr, sizeof(addr));
|
||||
net_tcp_set_blocking(sock);
|
||||
*/
|
||||
|
||||
|
@ -1216,7 +1216,7 @@ int fs_listdir(const char *dir, FS_LISTDIR_CALLBACK cb, int type, void *user)
|
|||
|
||||
if(!d)
|
||||
return 0;
|
||||
|
||||
|
||||
str_format(buffer, sizeof(buffer), "%s/", dir);
|
||||
length = str_length(buffer);
|
||||
|
||||
|
@ -1256,7 +1256,7 @@ int fs_storage_path(const char *appname, char *path, int max)
|
|||
for(i = strlen(home)+2; path[i]; i++)
|
||||
path[i] = tolower(path[i]);
|
||||
#endif
|
||||
|
||||
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
@ -1296,7 +1296,7 @@ int fs_is_dir(const char *path)
|
|||
struct stat sb;
|
||||
if (stat(path, &sb) == -1)
|
||||
return 0;
|
||||
|
||||
|
||||
if (S_ISDIR(sb.st_mode))
|
||||
return 1;
|
||||
else
|
||||
|
@ -1336,7 +1336,7 @@ int fs_parent_dir(char *path)
|
|||
if(*path == '/' || *path == '\\')
|
||||
parent = path;
|
||||
}
|
||||
|
||||
|
||||
if(parent)
|
||||
{
|
||||
*parent = 0;
|
||||
|
@ -1387,16 +1387,16 @@ void swap_endian(void *data, unsigned elem_size, unsigned num)
|
|||
|
||||
int net_socket_read_wait(NETSOCKET sock, int time)
|
||||
{
|
||||
struct timeval tv;
|
||||
fd_set readfds;
|
||||
struct timeval tv;
|
||||
fd_set readfds;
|
||||
int sockid;
|
||||
|
||||
tv.tv_sec = 0;
|
||||
tv.tv_usec = 1000*time;
|
||||
tv.tv_sec = 0;
|
||||
tv.tv_usec = 1000*time;
|
||||
sockid = 0;
|
||||
|
||||
FD_ZERO(&readfds);
|
||||
if(sock.ipv4sock >= 0)
|
||||
FD_ZERO(&readfds);
|
||||
if(sock.ipv4sock >= 0)
|
||||
{
|
||||
FD_SET(sock.ipv4sock, &readfds);
|
||||
sockid = sock.ipv4sock;
|
||||
|
@ -1408,8 +1408,8 @@ int net_socket_read_wait(NETSOCKET sock, int time)
|
|||
sockid = sock.ipv6sock;
|
||||
}
|
||||
|
||||
/* don't care about writefds and exceptfds */
|
||||
select(sockid+1, &readfds, NULL, NULL, &tv);
|
||||
/* don't care about writefds and exceptfds */
|
||||
select(sockid+1, &readfds, NULL, NULL, &tv);
|
||||
|
||||
if(sock.ipv4sock >= 0 && FD_ISSET(sock.ipv4sock, &readfds))
|
||||
return 1;
|
||||
|
@ -1417,7 +1417,7 @@ int net_socket_read_wait(NETSOCKET sock, int time)
|
|||
if(sock.ipv6sock >= 0 && FD_ISSET(sock.ipv6sock, &readfds))
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
unsigned time_timestamp()
|
||||
|
@ -1437,7 +1437,7 @@ void str_append(char *dst, const char *src, int dst_size)
|
|||
s++;
|
||||
i++;
|
||||
}
|
||||
|
||||
|
||||
dst[dst_size-1] = 0; /* assure null termination */
|
||||
}
|
||||
|
||||
|
@ -1458,12 +1458,12 @@ void str_format(char *buffer, int buffer_size, const char *format, ...)
|
|||
va_list ap;
|
||||
va_start(ap, format);
|
||||
_vsnprintf(buffer, buffer_size, format, ap);
|
||||
va_end(ap);
|
||||
va_end(ap);
|
||||
#else
|
||||
va_list ap;
|
||||
va_start(ap, format);
|
||||
vsnprintf(buffer, buffer_size, format, ap);
|
||||
va_end(ap);
|
||||
va_end(ap);
|
||||
#endif
|
||||
|
||||
buffer[buffer_size-1] = 0; /* assure null termination */
|
||||
|
@ -1588,7 +1588,7 @@ const char *str_find_nocase(const char *haystack, const char *needle)
|
|||
return haystack;
|
||||
haystack++;
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -1608,7 +1608,7 @@ const char *str_find(const char *haystack, const char *needle)
|
|||
return haystack;
|
||||
haystack++;
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -1630,7 +1630,7 @@ void str_timestamp(char *buffer, int buffer_size)
|
|||
{
|
||||
time_t time_data;
|
||||
struct tm *time_info;
|
||||
|
||||
|
||||
time(&time_data);
|
||||
time_info = localtime(&time_data);
|
||||
strftime(buffer, buffer_size, "%Y-%m-%d_%H-%M-%S", time_info);
|
||||
|
@ -1710,7 +1710,7 @@ float str_tofloat(const char *str) { return atof(str); }
|
|||
|
||||
static int str_utf8_isstart(char c)
|
||||
{
|
||||
if((c&0xC0) == 0x80) /* 10xxxxxx */
|
||||
if((c&0xC0) == 0x80) /* 10xxxxxx */
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
@ -1731,7 +1731,7 @@ int str_utf8_forward(const char *str, int cursor)
|
|||
const char *buf = str + cursor;
|
||||
if(!buf[0])
|
||||
return cursor;
|
||||
|
||||
|
||||
if((*buf&0x80) == 0x0) /* 0xxxxxxx */
|
||||
return cursor+1;
|
||||
else if((*buf&0xE0) == 0xC0) /* 110xxxxx */
|
||||
|
@ -1752,7 +1752,7 @@ int str_utf8_forward(const char *str, int cursor)
|
|||
if(!buf[3]) return cursor+3;
|
||||
return cursor+4;
|
||||
}
|
||||
|
||||
|
||||
/* invalid */
|
||||
return cursor+1;
|
||||
}
|
||||
|
@ -1786,7 +1786,7 @@ int str_utf8_encode(char *ptr, int chr)
|
|||
ptr[3] = 0x80|(chr&0x3F);
|
||||
return 4;
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -1794,7 +1794,7 @@ int str_utf8_decode(const char **ptr)
|
|||
{
|
||||
const char *buf = *ptr;
|
||||
int ch = 0;
|
||||
|
||||
|
||||
do
|
||||
{
|
||||
if((*buf&0x80) == 0x0) /* 0xxxxxxx */
|
||||
|
@ -1829,7 +1829,7 @@ int str_utf8_decode(const char **ptr)
|
|||
buf++;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
*ptr = buf;
|
||||
return ch;
|
||||
} while(0);
|
||||
|
@ -1837,7 +1837,7 @@ int str_utf8_decode(const char **ptr)
|
|||
/* out of bounds */
|
||||
*ptr = buf;
|
||||
return -1;
|
||||
|
||||
|
||||
}
|
||||
|
||||
int str_utf8_check(const char *str)
|
||||
|
@ -1845,7 +1845,7 @@ int str_utf8_check(const char *str)
|
|||
while(*str)
|
||||
{
|
||||
if((*str&0x80) == 0x0)
|
||||
str++;
|
||||
str++;
|
||||
else if((*str&0xE0) == 0xC0 && (*(str+1)&0xC0) == 0x80)
|
||||
str += 2;
|
||||
else if((*str&0xF0) == 0xE0 && (*(str+1)&0xC0) == 0x80 && (*(str+2)&0xC0) == 0x80)
|
||||
|
|
|
@ -18,28 +18,28 @@ extern "C" {
|
|||
/*
|
||||
Function: dbg_assert
|
||||
Breaks into the debugger based on a test.
|
||||
|
||||
|
||||
Parameters:
|
||||
test - Result of the test.
|
||||
msg - Message that should be printed if the test fails.
|
||||
|
||||
|
||||
Remarks:
|
||||
Does nothing in release version of the library.
|
||||
|
||||
|
||||
See Also:
|
||||
<dbg_break>
|
||||
*/
|
||||
void dbg_assert(int test, const char *msg);
|
||||
#define dbg_assert(test,msg) dbg_assert_imp(__FILE__, __LINE__, test, msg)
|
||||
#define dbg_assert(test,msg) dbg_assert_imp(__FILE__, __LINE__, test, msg)
|
||||
void dbg_assert_imp(const char *filename, int line, int test, const char *msg);
|
||||
|
||||
/*
|
||||
Function: dbg_break
|
||||
Breaks into the debugger.
|
||||
|
||||
|
||||
Remarks:
|
||||
Does nothing in release version of the library.
|
||||
|
||||
|
||||
See Also:
|
||||
<dbg_assert>
|
||||
*/
|
||||
|
@ -47,16 +47,16 @@ void dbg_break();
|
|||
|
||||
/*
|
||||
Function: dbg_msg
|
||||
|
||||
|
||||
Prints a debug message.
|
||||
|
||||
|
||||
Parameters:
|
||||
sys - A string that describes what system the message belongs to
|
||||
fmt - A printf styled format string.
|
||||
|
||||
|
||||
Remarks:
|
||||
Does nothing in release version of the library.
|
||||
|
||||
|
||||
See Also:
|
||||
<dbg_assert>
|
||||
*/
|
||||
|
@ -67,15 +67,15 @@ void dbg_msg(const char *sys, const char *fmt, ...);
|
|||
/*
|
||||
Function: mem_alloc
|
||||
Allocates memory.
|
||||
|
||||
|
||||
Parameters:
|
||||
size - Size of the needed block.
|
||||
alignment - Alignment for the block.
|
||||
|
||||
|
||||
Returns:
|
||||
Returns a pointer to the newly allocated block. Returns a
|
||||
null pointer if the memory couldn't be allocated.
|
||||
|
||||
|
||||
Remarks:
|
||||
- Passing 0 to size will allocated the smallest amount possible
|
||||
and return a unique pointer.
|
||||
|
@ -89,12 +89,12 @@ void *mem_alloc_debug(const char *filename, int line, unsigned size, unsigned al
|
|||
/*
|
||||
Function: mem_free
|
||||
Frees a block allocated through <mem_alloc>.
|
||||
|
||||
|
||||
Remarks:
|
||||
- In the debug version of the library the function will assert if
|
||||
a non-valid block is passed, like a null pointer or a block that
|
||||
isn't allocated.
|
||||
|
||||
|
||||
See Also:
|
||||
<mem_alloc>
|
||||
*/
|
||||
|
@ -103,16 +103,16 @@ void mem_free(void *block);
|
|||
/*
|
||||
Function: mem_copy
|
||||
Copies a a memory block.
|
||||
|
||||
|
||||
Parameters:
|
||||
dest - Destination.
|
||||
source - Source to copy.
|
||||
size - Size of the block to copy.
|
||||
|
||||
|
||||
Remarks:
|
||||
- This functions DOES NOT handles cases where source and
|
||||
destination is overlapping.
|
||||
|
||||
|
||||
See Also:
|
||||
<mem_move>
|
||||
*/
|
||||
|
@ -121,16 +121,16 @@ void mem_copy(void *dest, const void *source, unsigned size);
|
|||
/*
|
||||
Function: mem_move
|
||||
Copies a a memory block
|
||||
|
||||
|
||||
Parameters:
|
||||
dest - Destination
|
||||
source - Source to copy
|
||||
size - Size of the block to copy
|
||||
|
||||
|
||||
Remarks:
|
||||
- This functions handles cases where source and destination
|
||||
is overlapping
|
||||
|
||||
|
||||
See Also:
|
||||
<mem_copy>
|
||||
*/
|
||||
|
@ -139,7 +139,7 @@ void mem_move(void *dest, const void *source, unsigned size);
|
|||
/*
|
||||
Function: mem_zero
|
||||
Sets a complete memory block to 0
|
||||
|
||||
|
||||
Parameters:
|
||||
block - Pointer to the block to zero out
|
||||
size - Size of the block
|
||||
|
@ -149,12 +149,12 @@ void mem_zero(void *block, unsigned size);
|
|||
/*
|
||||
Function: mem_comp
|
||||
Compares two blocks of memory
|
||||
|
||||
|
||||
Parameters:
|
||||
a - First block of data
|
||||
b - Second block of data
|
||||
size - Size of the data to compare
|
||||
|
||||
|
||||
Returns:
|
||||
<0 - Block a is lesser then block b
|
||||
0 - Block a is equal to block b
|
||||
|
@ -168,7 +168,7 @@ int mem_comp(const void *a, const void *b, int size);
|
|||
Will trigger a assert if memory has failed.
|
||||
*/
|
||||
int mem_check_imp();
|
||||
#define mem_check() dbg_assert_imp(__FILE__, __LINE__, mem_check_imp(), "Memory check failed")
|
||||
#define mem_check() dbg_assert_imp(__FILE__, __LINE__, mem_check_imp(), "Memory check failed")
|
||||
|
||||
/* Group: File IO */
|
||||
enum {
|
||||
|
@ -205,7 +205,7 @@ IOHANDLE io_open(const char *filename, int flags);
|
|||
io - Handle to the file to read data from.
|
||||
buffer - Pointer to the buffer that will recive the data.
|
||||
size - Number of bytes to read from the file.
|
||||
|
||||
|
||||
Returns:
|
||||
Number of bytes read.
|
||||
|
||||
|
@ -215,11 +215,11 @@ unsigned io_read(IOHANDLE io, void *buffer, unsigned size);
|
|||
/*
|
||||
Function: io_skip
|
||||
Skips data in a file.
|
||||
|
||||
|
||||
Parameters:
|
||||
io - Handle to the file.
|
||||
size - Number of bytes to skip.
|
||||
|
||||
|
||||
Returns:
|
||||
Number of bytes skipped.
|
||||
*/
|
||||
|
@ -228,12 +228,12 @@ unsigned io_skip(IOHANDLE io, int size);
|
|||
/*
|
||||
Function: io_write
|
||||
Writes data from a buffer to file.
|
||||
|
||||
|
||||
Parameters:
|
||||
io - Handle to the file.
|
||||
buffer - Pointer to the data that should be written.
|
||||
size - Number of bytes to write.
|
||||
|
||||
|
||||
Returns:
|
||||
Number of bytes written.
|
||||
*/
|
||||
|
@ -242,12 +242,12 @@ unsigned io_write(IOHANDLE io, const void *buffer, unsigned size);
|
|||
/*
|
||||
Function: io_seek
|
||||
Seeks to a specified offset in the file.
|
||||
|
||||
|
||||
Parameters:
|
||||
io - Handle to the file.
|
||||
offset - Offset from pos to stop.
|
||||
origin - Position to start searching from.
|
||||
|
||||
|
||||
Returns:
|
||||
Returns 0 on success.
|
||||
*/
|
||||
|
@ -256,10 +256,10 @@ int io_seek(IOHANDLE io, int offset, int origin);
|
|||
/*
|
||||
Function: io_tell
|
||||
Gets the current position in the file.
|
||||
|
||||
|
||||
Parameters:
|
||||
io - Handle to the file.
|
||||
|
||||
|
||||
Returns:
|
||||
Returns the current position. -1L if an error occured.
|
||||
*/
|
||||
|
@ -268,10 +268,10 @@ long int io_tell(IOHANDLE io);
|
|||
/*
|
||||
Function: io_length
|
||||
Gets the total length of the file. Resetting cursor to the beginning
|
||||
|
||||
|
||||
Parameters:
|
||||
io - Handle to the file.
|
||||
|
||||
|
||||
Returns:
|
||||
Returns the total size. -1L if an error occured.
|
||||
*/
|
||||
|
@ -280,10 +280,10 @@ long int io_length(IOHANDLE io);
|
|||
/*
|
||||
Function: io_close
|
||||
Closes a file.
|
||||
|
||||
|
||||
Parameters:
|
||||
io - Handle to the file.
|
||||
|
||||
|
||||
Returns:
|
||||
Returns 0 on success.
|
||||
*/
|
||||
|
@ -292,10 +292,10 @@ int io_close(IOHANDLE io);
|
|||
/*
|
||||
Function: io_flush
|
||||
Empties all buffers and writes all pending data.
|
||||
|
||||
|
||||
Parameters:
|
||||
io - Handle to the file.
|
||||
|
||||
|
||||
Returns:
|
||||
Returns 0 on success.
|
||||
*/
|
||||
|
@ -326,7 +326,7 @@ IOHANDLE io_stderr();
|
|||
/*
|
||||
Function: thread_sleep
|
||||
Suspends the current thread for a given period.
|
||||
|
||||
|
||||
Parameters:
|
||||
milliseconds - Number of milliseconds to sleep.
|
||||
*/
|
||||
|
@ -335,18 +335,18 @@ void thread_sleep(int milliseconds);
|
|||
/*
|
||||
Function: thread_create
|
||||
Creates a new thread.
|
||||
|
||||
|
||||
Parameters:
|
||||
threadfunc - Entry point for the new thread.
|
||||
user - Pointer to pass to the thread.
|
||||
|
||||
|
||||
*/
|
||||
void *thread_create(void (*threadfunc)(void *), void *user);
|
||||
|
||||
/*
|
||||
Function: thread_wait
|
||||
Waits for a thread to be done or destroyed.
|
||||
|
||||
|
||||
Parameters:
|
||||
thread - Thread to wait for.
|
||||
*/
|
||||
|
@ -355,7 +355,7 @@ void thread_wait(void *thread);
|
|||
/*
|
||||
Function: thread_destroy
|
||||
Destroys a thread.
|
||||
|
||||
|
||||
Parameters:
|
||||
thread - Thread to destroy.
|
||||
*/
|
||||
|
@ -390,7 +390,7 @@ typedef long long int64;
|
|||
/*
|
||||
Function: time_get
|
||||
Fetches a sample from a high resolution timer.
|
||||
|
||||
|
||||
Returns:
|
||||
Current value of the timer.
|
||||
|
||||
|
@ -402,7 +402,7 @@ int64 time_get();
|
|||
/*
|
||||
Function: time_freq
|
||||
Returns the frequency of the high resolution timer.
|
||||
|
||||
|
||||
Returns:
|
||||
Returns the frequency of the high resolution timer.
|
||||
*/
|
||||
|
@ -411,7 +411,7 @@ int64 time_freq();
|
|||
/*
|
||||
Function: time_timestamp
|
||||
Retrives the current time as a UNIX timestamp
|
||||
|
||||
|
||||
Returns:
|
||||
The time as a UNIX timestamp
|
||||
*/
|
||||
|
@ -428,7 +428,7 @@ typedef struct
|
|||
enum
|
||||
{
|
||||
NETADDR_MAXSTRSIZE = 1+(8*4+7)+1+1+5+1, // [XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX]:XXXXX
|
||||
|
||||
|
||||
NETTYPE_INVALID = 0,
|
||||
NETTYPE_IPV4 = 1,
|
||||
NETTYPE_IPV6 = 2,
|
||||
|
@ -446,10 +446,10 @@ typedef struct
|
|||
/*
|
||||
Function: net_init
|
||||
Initiates network functionallity.
|
||||
|
||||
|
||||
Returns:
|
||||
Returns 0 on success,
|
||||
|
||||
|
||||
Remarks:
|
||||
You must call this function before using any other network
|
||||
functions.
|
||||
|
@ -469,11 +469,11 @@ int net_host_lookup(const char *hostname, NETADDR *addr, int types);
|
|||
/*
|
||||
Function: net_addr_comp
|
||||
Compares two network addresses.
|
||||
|
||||
|
||||
Parameters:
|
||||
a - Address to compare
|
||||
b - Address to compare to.
|
||||
|
||||
|
||||
Returns:
|
||||
<0 - Address a is lesser then address b
|
||||
0 - Address a is equal to address b
|
||||
|
@ -484,12 +484,12 @@ int net_addr_comp(const NETADDR *a, const NETADDR *b);
|
|||
/*
|
||||
Function: net_addr_str
|
||||
Turns a network address into a representive string.
|
||||
|
||||
|
||||
Parameters:
|
||||
addr - Address to turn into a string.
|
||||
string - Buffer to fill with the string.
|
||||
max_length - Maximum size of the string.
|
||||
|
||||
|
||||
Remarks:
|
||||
- The string will always be zero terminated
|
||||
|
||||
|
@ -499,10 +499,10 @@ void net_addr_str(const NETADDR *addr, char *string, int max_length);
|
|||
/*
|
||||
Function: net_addr_from_str
|
||||
Turns string into a network address.
|
||||
|
||||
|
||||
Returns:
|
||||
0 on success
|
||||
|
||||
|
||||
Parameters:
|
||||
addr - Address to fill in.
|
||||
string - String to parse.
|
||||
|
@ -517,7 +517,7 @@ int net_addr_from_str(NETADDR *addr, const char *string);
|
|||
|
||||
Parameters:
|
||||
bindaddr - Address to bind the socket to.
|
||||
|
||||
|
||||
Returns:
|
||||
On success it returns an handle to the socket. On failure it
|
||||
returns NETSOCKET_INVALID.
|
||||
|
@ -533,7 +533,7 @@ NETSOCKET net_udp_create(NETADDR bindaddr);
|
|||
addr - Where to send the packet.
|
||||
data - Pointer to the packet data to send.
|
||||
size - Size of the packet.
|
||||
|
||||
|
||||
Returns:
|
||||
On success it returns the number of bytes sent. Returns -1
|
||||
on error.
|
||||
|
@ -549,7 +549,7 @@ int net_udp_send(NETSOCKET sock, const NETADDR *addr, const void *data, int size
|
|||
addr - Pointer to an NETADDR that will recive the address.
|
||||
data - Pointer to a buffer that will recive the data.
|
||||
maxsize - Maximum size to recive.
|
||||
|
||||
|
||||
Returns:
|
||||
On success it returns the number of bytes recived. Returns -1
|
||||
on error.
|
||||
|
@ -562,7 +562,7 @@ int net_udp_recv(NETSOCKET sock, NETADDR *addr, void *data, int maxsize);
|
|||
|
||||
Parameters:
|
||||
sock - Socket to close.
|
||||
|
||||
|
||||
Returns:
|
||||
Returns 0 on success. -1 on error.
|
||||
*/
|
||||
|
@ -574,7 +574,7 @@ int net_udp_close(NETSOCKET sock);
|
|||
/*
|
||||
Function: net_tcp_create
|
||||
Creates a TCP socket.
|
||||
|
||||
|
||||
Parameters:
|
||||
bindaddr - Address to bind the socket to.
|
||||
|
||||
|
@ -586,11 +586,11 @@ NETSOCKET net_tcp_create(const NETADDR *a);
|
|||
/*
|
||||
Function: net_tcp_listen
|
||||
Makes the socket start listening for new connections.
|
||||
|
||||
|
||||
Parameters:
|
||||
sock - Socket to start listen to.
|
||||
backlog - Size of the queue of incomming connections to keep.
|
||||
|
||||
|
||||
Returns:
|
||||
Returns 0 on success.
|
||||
*/
|
||||
|
@ -599,12 +599,12 @@ int net_tcp_listen(NETSOCKET sock, int backlog);
|
|||
/*
|
||||
Function: net_tcp_accept
|
||||
Polls a listning socket for a new connection.
|
||||
|
||||
|
||||
Parameters:
|
||||
sock - Listning socket to poll.
|
||||
new_sock - Pointer to a socket to fill in with the new socket.
|
||||
addr - Pointer to an address that will be filled in the remote address (optional, can be NULL).
|
||||
|
||||
|
||||
Returns:
|
||||
Returns a non-negative integer on success. Negative integer on failure.
|
||||
*/
|
||||
|
@ -613,26 +613,26 @@ int net_tcp_accept(NETSOCKET sock, NETSOCKET *new_sock, NETADDR *addr);
|
|||
/*
|
||||
Function: net_tcp_connect
|
||||
Connects one socket to another.
|
||||
|
||||
|
||||
Parameters:
|
||||
sock - Socket to connect.
|
||||
addr - Address to connect to.
|
||||
|
||||
Returns:
|
||||
Returns 0 on success.
|
||||
|
||||
|
||||
*/
|
||||
int net_tcp_connect(NETSOCKET sock, const NETADDR *addr);
|
||||
|
||||
/*
|
||||
Function: net_tcp_send
|
||||
Sends data to a TCP stream.
|
||||
|
||||
|
||||
Parameters:
|
||||
sock - Socket to send data to.
|
||||
data - Pointer to the data to send.
|
||||
size - Size of the data to send.
|
||||
|
||||
|
||||
Returns:
|
||||
Number of bytes sent. Negative value on failure.
|
||||
*/
|
||||
|
@ -641,12 +641,12 @@ int net_tcp_send(NETSOCKET sock, const void *data, int size);
|
|||
/*
|
||||
Function: net_tcp_recv
|
||||
Recvives data from a TCP stream.
|
||||
|
||||
|
||||
Parameters:
|
||||
sock - Socket to recvive data from.
|
||||
data - Pointer to a buffer to write the data to
|
||||
max_size - Maximum of data to write to the buffer.
|
||||
|
||||
|
||||
Returns:
|
||||
Number of bytes recvived. Negative value on failure. When in
|
||||
non-blocking mode, it returns 0 when there is no more data to
|
||||
|
@ -657,10 +657,10 @@ int net_tcp_recv(NETSOCKET sock, void *data, int maxsize);
|
|||
/*
|
||||
Function: net_tcp_close
|
||||
Closes a TCP socket.
|
||||
|
||||
|
||||
Parameters:
|
||||
sock - Socket to close.
|
||||
|
||||
|
||||
Returns:
|
||||
Returns 0 on success. Negative value on failure.
|
||||
*/
|
||||
|
@ -671,12 +671,12 @@ int net_tcp_close(NETSOCKET sock);
|
|||
/*
|
||||
Function: str_append
|
||||
Appends a string to another.
|
||||
|
||||
|
||||
Parameters:
|
||||
dst - Pointer to a buffer that contains a string.
|
||||
src - String to append.
|
||||
dst_size - Size of the buffer of the dst string.
|
||||
|
||||
|
||||
Remarks:
|
||||
- The strings are treated as zero-termineted strings.
|
||||
- Garantees that dst string will contain zero-termination.
|
||||
|
@ -686,7 +686,7 @@ void str_append(char *dst, const char *src, int dst_size);
|
|||
/*
|
||||
Function: str_copy
|
||||
Copies a string to another.
|
||||
|
||||
|
||||
Parameters:
|
||||
dst - Pointer to a buffer that shall recive the string.
|
||||
src - String to be copied.
|
||||
|
@ -701,10 +701,10 @@ void str_copy(char *dst, const char *src, int dst_size);
|
|||
/*
|
||||
Function: str_length
|
||||
Returns the length of a zero terminated string.
|
||||
|
||||
|
||||
Parameters:
|
||||
str - Pointer to the string.
|
||||
|
||||
|
||||
Returns:
|
||||
Length of string in bytes excluding the zero termination.
|
||||
*/
|
||||
|
@ -713,7 +713,7 @@ int str_length(const char *str);
|
|||
/*
|
||||
Function: str_format
|
||||
Performs printf formating into a buffer.
|
||||
|
||||
|
||||
Parameters:
|
||||
buffer - Pointer to the buffer to recive the formated string.
|
||||
buffer_size - Size of the buffer.
|
||||
|
@ -730,7 +730,7 @@ void str_format(char *buffer, int buffer_size, const char *format, ...);
|
|||
/*
|
||||
Function: str_sanitize_strong
|
||||
Replaces all characters below 32 and above 127 with whitespace.
|
||||
|
||||
|
||||
Parameters:
|
||||
str - String to sanitize.
|
||||
|
||||
|
@ -742,7 +742,7 @@ void str_sanitize_strong(char *str);
|
|||
/*
|
||||
Function: str_sanitize_cc
|
||||
Replaces all characters below 32 with whitespace.
|
||||
|
||||
|
||||
Parameters:
|
||||
str - String to sanitize.
|
||||
|
||||
|
@ -755,7 +755,7 @@ void str_sanitize_cc(char *str);
|
|||
Function: str_sanitize
|
||||
Replaces all characters below 32 with whitespace with
|
||||
exception to \t, \n and \r.
|
||||
|
||||
|
||||
Parameters:
|
||||
str - String to sanitize.
|
||||
|
||||
|
@ -767,7 +767,7 @@ void str_sanitize(char *str);
|
|||
/*
|
||||
Function: str_skip_to_whitespace
|
||||
Skips leading non-whitespace characters(all but ' ', '\t', '\n', '\r').
|
||||
|
||||
|
||||
Parameters:
|
||||
str - Pointer to the string.
|
||||
|
||||
|
@ -783,7 +783,7 @@ char *str_skip_to_whitespace(char *str);
|
|||
/*
|
||||
Function: str_skip_whitespaces
|
||||
Skips leading whitespace characters(' ', '\t', '\n', '\r').
|
||||
|
||||
|
||||
Parameters:
|
||||
str - Pointer to the string.
|
||||
|
||||
|
@ -799,12 +799,12 @@ char *str_skip_whitespaces(char *str);
|
|||
/*
|
||||
Function: str_comp_nocase
|
||||
Compares to strings case insensitive.
|
||||
|
||||
|
||||
Parameters:
|
||||
a - String to compare.
|
||||
b - String to compare.
|
||||
|
||||
Returns:
|
||||
|
||||
Returns:
|
||||
<0 - String a is lesser then string b
|
||||
0 - String a is equal to string b
|
||||
>0 - String a is greater then string b
|
||||
|
@ -819,12 +819,12 @@ int str_comp_nocase(const char *a, const char *b);
|
|||
/*
|
||||
Function: str_comp
|
||||
Compares to strings case sensitive.
|
||||
|
||||
|
||||
Parameters:
|
||||
a - String to compare.
|
||||
b - String to compare.
|
||||
|
||||
Returns:
|
||||
|
||||
Returns:
|
||||
<0 - String a is lesser then string b
|
||||
0 - String a is equal to string b
|
||||
>0 - String a is greater then string b
|
||||
|
@ -837,13 +837,13 @@ int str_comp(const char *a, const char *b);
|
|||
/*
|
||||
Function: str_comp_num
|
||||
Compares up to num characters of two strings case sensitive.
|
||||
|
||||
|
||||
Parameters:
|
||||
a - String to compare.
|
||||
b - String to compare.
|
||||
num - Maximum characters to compare
|
||||
|
||||
Returns:
|
||||
|
||||
Returns:
|
||||
<0 - String a is lesser then string b
|
||||
0 - String a is equal to string b
|
||||
>0 - String a is greater then string b
|
||||
|
@ -856,12 +856,12 @@ int str_comp_num(const char *a, const char *b, const int num);
|
|||
/*
|
||||
Function: str_comp_filenames
|
||||
Compares two strings case sensitive, digit chars will be compared as numbers.
|
||||
|
||||
|
||||
Parameters:
|
||||
a - String to compare.
|
||||
b - String to compare.
|
||||
|
||||
Returns:
|
||||
|
||||
Returns:
|
||||
<0 - String a is lesser then string b
|
||||
0 - String a is equal to string b
|
||||
>0 - String a is greater then string b
|
||||
|
@ -878,7 +878,7 @@ int str_comp_filenames(const char *a, const char *b);
|
|||
Parameters:
|
||||
haystack - String to search in
|
||||
needle - String to search for
|
||||
|
||||
|
||||
Returns:
|
||||
A pointer into haystack where the needle was found.
|
||||
Returns NULL of needle could not be found.
|
||||
|
@ -896,7 +896,7 @@ const char *str_find_nocase(const char *haystack, const char *needle);
|
|||
Parameters:
|
||||
haystack - String to search in
|
||||
needle - String to search for
|
||||
|
||||
|
||||
Returns:
|
||||
A pointer into haystack where the needle was found.
|
||||
Returns NULL of needle could not be found.
|
||||
|
@ -939,13 +939,13 @@ void str_timestamp(char *buffer, int buffer_size);
|
|||
/*
|
||||
Function: fs_listdir
|
||||
Lists the files in a directory
|
||||
|
||||
|
||||
Parameters:
|
||||
dir - Directory to list
|
||||
cb - Callback function to call for each entry
|
||||
type - Type of the directory
|
||||
user - Pointer to give to the callback
|
||||
|
||||
|
||||
Returns:
|
||||
Always returns 0.
|
||||
*/
|
||||
|
@ -955,13 +955,13 @@ int fs_listdir(const char *dir, FS_LISTDIR_CALLBACK cb, int type, void *user);
|
|||
/*
|
||||
Function: fs_makedir
|
||||
Creates a directory
|
||||
|
||||
|
||||
Parameters:
|
||||
path - Directory to create
|
||||
|
||||
|
||||
Returns:
|
||||
Returns 0 on success. Negative value on failure.
|
||||
|
||||
|
||||
Remarks:
|
||||
Does not create several directories if needed. "a/b/c" will result
|
||||
in a failure if b or a does not exist.
|
||||
|
@ -971,10 +971,10 @@ int fs_makedir(const char *path);
|
|||
/*
|
||||
Function: fs_storage_path
|
||||
Fetches per user configuration directory.
|
||||
|
||||
|
||||
Returns:
|
||||
Returns 0 on success. Negative value on failure.
|
||||
|
||||
|
||||
Remarks:
|
||||
- Returns ~/.appname on UNIX based systems
|
||||
- Returns ~/Library/Applications Support/appname on Mac OS X
|
||||
|
@ -985,7 +985,7 @@ int fs_storage_path(const char *appname, char *path, int max);
|
|||
/*
|
||||
Function: fs_is_dir
|
||||
Checks if directory exists
|
||||
|
||||
|
||||
Returns:
|
||||
Returns 1 on success, 0 on failure.
|
||||
*/
|
||||
|
@ -994,7 +994,7 @@ int fs_is_dir(const char *path);
|
|||
/*
|
||||
Function: fs_chdir
|
||||
Changes current working directory
|
||||
|
||||
|
||||
Returns:
|
||||
Returns 0 on success, 1 on failure.
|
||||
*/
|
||||
|
@ -1003,7 +1003,7 @@ int fs_chdir(const char *path);
|
|||
/*
|
||||
Function: fs_getcwd
|
||||
Gets the current working directory.
|
||||
|
||||
|
||||
Returns:
|
||||
Returns a pointer to the buffer on success, 0 on failure.
|
||||
*/
|
||||
|
@ -1012,7 +1012,7 @@ char *fs_getcwd(char *buffer, int buffer_size);
|
|||
/*
|
||||
Function: fs_parent_dir
|
||||
Get the parent directory of a directory
|
||||
|
||||
|
||||
Parameters:
|
||||
path - The directory string
|
||||
|
||||
|
@ -1027,7 +1027,7 @@ int fs_parent_dir(char *path);
|
|||
/*
|
||||
Function: fs_remove
|
||||
Deletes the file with the specified name.
|
||||
|
||||
|
||||
Parameters:
|
||||
filename - The file to delete
|
||||
|
||||
|
@ -1042,7 +1042,7 @@ int fs_remove(const char *filename);
|
|||
/*
|
||||
Function: fs_rename
|
||||
Renames the file or directory. If the paths differ the file will be moved.
|
||||
|
||||
|
||||
Parameters:
|
||||
oldname - The actual name
|
||||
newname - The new name
|
||||
|
@ -1062,7 +1062,7 @@ int fs_rename(const char *oldname, const char *newname);
|
|||
|
||||
/*
|
||||
Function: net_tcp_connect_non_blocking
|
||||
|
||||
|
||||
DOCTODO: serp
|
||||
*/
|
||||
int net_tcp_connect_non_blocking(NETSOCKET sock, const NETADDR *a);
|
||||
|
@ -1121,7 +1121,7 @@ enum {
|
|||
#define DBG_LEVEL_LOW DBG_LEVEL_IMPORTANT
|
||||
#define DBG_LEVEL_HIGH DBG_LEVEL_INFO
|
||||
|
||||
typedef void (*DBG_LOGGER)(const char *line);
|
||||
typedef void (*DBG_LOGGER)(const char *line);
|
||||
void dbg_logger(DBG_LOGGER logger);
|
||||
|
||||
void dbg_logger_stdout();
|
||||
|
@ -1157,7 +1157,7 @@ unsigned str_quickhash(const char *str);
|
|||
/*
|
||||
Function: gui_messagebox
|
||||
Display plain OS-dependent message box
|
||||
|
||||
|
||||
Parameters:
|
||||
title - title of the message box
|
||||
message - text to display
|
||||
|
@ -1168,7 +1168,7 @@ void gui_messagebox(const char *title, const char *message);
|
|||
/*
|
||||
Function: str_utf8_rewind
|
||||
Moves a cursor backwards in an utf8 string
|
||||
|
||||
|
||||
Parameters:
|
||||
str - utf8 string
|
||||
cursor - position in the string
|
||||
|
@ -1184,11 +1184,11 @@ int str_utf8_rewind(const char *str, int cursor);
|
|||
/*
|
||||
Function: str_utf8_forward
|
||||
Moves a cursor forwards in an utf8 string
|
||||
|
||||
|
||||
Parameters:
|
||||
str - utf8 string
|
||||
cursor - position in the string
|
||||
|
||||
|
||||
Returns:
|
||||
New cursor position.
|
||||
|
||||
|
@ -1200,10 +1200,10 @@ int str_utf8_forward(const char *str, int cursor);
|
|||
/*
|
||||
Function: str_utf8_decode
|
||||
Decodes an utf8 character
|
||||
|
||||
|
||||
Parameters:
|
||||
ptr - pointer to an utf8 string. this pointer will be moved forward
|
||||
|
||||
|
||||
Returns:
|
||||
Unicode value for the character. -1 for invalid characters and 0 for end of string.
|
||||
|
||||
|
@ -1215,10 +1215,10 @@ int str_utf8_decode(const char **ptr);
|
|||
/*
|
||||
Function: str_utf8_encode
|
||||
Encode an utf8 character
|
||||
|
||||
|
||||
Parameters:
|
||||
ptr - Pointer to a buffer that should recive the data. Should be able to hold at least 4 bytes.
|
||||
|
||||
|
||||
Returns:
|
||||
Number of bytes put into the buffer.
|
||||
|
||||
|
@ -1230,10 +1230,10 @@ int str_utf8_encode(char *ptr, int chr);
|
|||
/*
|
||||
Function: str_utf8_check
|
||||
Checks if a strings contains just valid utf8 characters.
|
||||
|
||||
|
||||
Parameters:
|
||||
str - Pointer to a possible utf8 string.
|
||||
|
||||
|
||||
Returns:
|
||||
0 - invalid characters found.
|
||||
1 - only valid characters found.
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
|
||||
/* If you are missing that file, acquire a complete release at teeworlds.com. */
|
||||
#ifndef TL_FILE_ALGORITHM_HPP
|
||||
#define TL_FILE_ALGORITHM_HPP
|
||||
#ifndef BASE_TL_ALGORITHM_H
|
||||
#define BASE_TL_ALGORITHM_H
|
||||
|
||||
#include "range.h"
|
||||
|
||||
|
||||
/*
|
||||
insert 4
|
||||
v
|
||||
v
|
||||
1 2 3 4 5 6
|
||||
|
||||
*/
|
||||
|
@ -38,12 +38,12 @@ R partition_binary(R range, T value)
|
|||
concept_size::check(range);
|
||||
concept_slice::check(range);
|
||||
concept_sorted::check(range);
|
||||
|
||||
|
||||
if(range.empty())
|
||||
return range;
|
||||
if(range.back() < value)
|
||||
return R();
|
||||
|
||||
|
||||
while(range.size() > 1)
|
||||
{
|
||||
unsigned pivot = (range.size()-1)/2;
|
||||
|
@ -82,7 +82,7 @@ void sort_bubble(R range)
|
|||
concept_empty::check(range);
|
||||
concept_forwarditeration::check(range);
|
||||
concept_backwarditeration::check(range);
|
||||
|
||||
|
||||
// slow bubblesort :/
|
||||
for(; !range.empty(); range.pop_back())
|
||||
{
|
||||
|
@ -119,18 +119,18 @@ bool sort_verify(R range)
|
|||
{
|
||||
concept_empty::check(range);
|
||||
concept_forwarditeration::check(range);
|
||||
|
||||
|
||||
typename R::type *prev = &range.front();
|
||||
range.pop_front();
|
||||
for(; !range.empty(); range.pop_front())
|
||||
{
|
||||
typename R::type *cur = &range.front();
|
||||
|
||||
|
||||
if(*cur < *prev)
|
||||
return false;
|
||||
prev = cur;
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
|
||||
/* If you are missing that file, acquire a complete release at teeworlds.com. */
|
||||
#ifndef TL_FILE_ALLOCATOR_HPP
|
||||
#define TL_FILE_ALLOCATOR_HPP
|
||||
#ifndef BASE_TL_ALLOCATOR_H
|
||||
#define BASE_TL_ALLOCATOR_H
|
||||
|
||||
template <class T>
|
||||
class allocator_default
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
|
||||
/* If you are missing that file, acquire a complete release at teeworlds.com. */
|
||||
#ifndef TL_FILE_ARRAY_HPP
|
||||
#define TL_FILE_ARRAY_HPP
|
||||
#ifndef BASE_TL_ARRAY_H
|
||||
#define BASE_TL_ARRAY_H
|
||||
|
||||
#include "range.h"
|
||||
#include "allocator.h"
|
||||
|
@ -10,10 +10,10 @@
|
|||
/*
|
||||
Class: array
|
||||
Normal dynamic array class
|
||||
|
||||
|
||||
Remarks:
|
||||
- Grows 50% each time it needs to fit new items
|
||||
- Use set_size() if you know how many elements
|
||||
- Use set_size() if you know how many elements
|
||||
- Use optimize() to reduce the needed space.
|
||||
*/
|
||||
template <class T, class ALLOCATOR = allocator_default<T> >
|
||||
|
@ -24,7 +24,7 @@ class array : private ALLOCATOR
|
|||
list = 0x0;
|
||||
clear();
|
||||
}
|
||||
|
||||
|
||||
public:
|
||||
typedef plain_range<T> range;
|
||||
|
||||
|
@ -35,7 +35,7 @@ public:
|
|||
{
|
||||
init();
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Function: array copy constructor
|
||||
*/
|
||||
|
@ -60,7 +60,7 @@ public:
|
|||
|
||||
/*
|
||||
Function: delete_all
|
||||
|
||||
|
||||
Remarks:
|
||||
- Invalidates ranges
|
||||
*/
|
||||
|
@ -74,7 +74,7 @@ public:
|
|||
|
||||
/*
|
||||
Function: clear
|
||||
|
||||
|
||||
Remarks:
|
||||
- Invalidates ranges
|
||||
*/
|
||||
|
@ -124,7 +124,7 @@ public:
|
|||
|
||||
/*
|
||||
Function: remove_index
|
||||
|
||||
|
||||
Remarks:
|
||||
- Invalidates ranges
|
||||
*/
|
||||
|
@ -132,7 +132,7 @@ public:
|
|||
{
|
||||
for(int i = index+1; i < num_elements; i++)
|
||||
list[i-1] = list[i];
|
||||
|
||||
|
||||
set_size(size()-1);
|
||||
}
|
||||
|
||||
|
@ -156,10 +156,10 @@ public:
|
|||
/*
|
||||
Function: add
|
||||
Adds an item to the array.
|
||||
|
||||
|
||||
Arguments:
|
||||
item - Item to add.
|
||||
|
||||
|
||||
Remarks:
|
||||
- Invalidates ranges
|
||||
- See remarks about <array> how the array grows.
|
||||
|
@ -175,9 +175,9 @@ public:
|
|||
/*
|
||||
Function: insert
|
||||
Inserts an item into the array at a specified location.
|
||||
|
||||
|
||||
Arguments:
|
||||
item - Item to insert.
|
||||
item - Item to insert.
|
||||
r - Range where to insert the item
|
||||
|
||||
Remarks:
|
||||
|
@ -188,16 +188,16 @@ public:
|
|||
{
|
||||
if(r.empty())
|
||||
return add(item);
|
||||
|
||||
|
||||
int index = (int)(&r.front()-list);
|
||||
incsize();
|
||||
set_size(size()+1);
|
||||
|
||||
|
||||
for(int i = num_elements-1; i > index; i--)
|
||||
list[i] = list[i-1];
|
||||
|
||||
list[index] = item;
|
||||
|
||||
|
||||
return num_elements-1;
|
||||
}
|
||||
|
||||
|
@ -236,7 +236,7 @@ public:
|
|||
/*
|
||||
Function: set_size
|
||||
Resizes the array to the specified size.
|
||||
|
||||
|
||||
Arguments:
|
||||
new_size - The new size for the array.
|
||||
*/
|
||||
|
@ -251,10 +251,10 @@ public:
|
|||
Function: hint_size
|
||||
Allocates the number of elements wanted but
|
||||
does not increase the list size.
|
||||
|
||||
|
||||
Arguments:
|
||||
hint - Size to allocate.
|
||||
|
||||
|
||||
Remarks:
|
||||
- If the hint is smaller then the number of elements, nothing will be done.
|
||||
- Invalidates ranges
|
||||
|
@ -302,7 +302,7 @@ public:
|
|||
(*this)[i] = other[i];
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Function: all
|
||||
Returns a range that contains the whole array.
|
||||
|
@ -318,18 +318,18 @@ protected:
|
|||
alloc(list_size+1);
|
||||
else
|
||||
alloc(list_size+list_size/2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void alloc(int new_len)
|
||||
{
|
||||
list_size = new_len;
|
||||
T *new_list = ALLOCATOR::alloc_array(list_size);
|
||||
|
||||
|
||||
int end = num_elements < list_size ? num_elements : list_size;
|
||||
for(int i = 0; i < end; i++)
|
||||
new_list[i] = list[i];
|
||||
|
||||
|
||||
ALLOCATOR::free_array(list);
|
||||
|
||||
num_elements = num_elements < list_size ? num_elements : list_size;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
|
||||
/* If you are missing that file, acquire a complete release at teeworlds.com. */
|
||||
#ifndef TL_FILE_BASE_HPP
|
||||
#define TL_FILE_BASE_HPP
|
||||
#ifndef BASE_TL_BASE_H
|
||||
#define BASE_TL_BASE_H
|
||||
|
||||
#include <base/system.h>
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
|
||||
/* If you are missing that file, acquire a complete release at teeworlds.com. */
|
||||
#ifndef TL_FILE_RANGE_HPP
|
||||
#define TL_FILE_RANGE_HPP
|
||||
#ifndef BASE_TL_RANGE_H
|
||||
#define BASE_TL_RANGE_H
|
||||
|
||||
#include "base.h"
|
||||
|
||||
|
@ -11,7 +11,7 @@
|
|||
|
||||
/*
|
||||
Concept: concept_empty
|
||||
|
||||
|
||||
template<class T>
|
||||
struct range
|
||||
{
|
||||
|
@ -25,7 +25,7 @@ struct concept_empty
|
|||
|
||||
/*
|
||||
Concept: concept_index
|
||||
|
||||
|
||||
template<class T>
|
||||
struct range
|
||||
{
|
||||
|
@ -39,7 +39,7 @@ struct concept_index
|
|||
|
||||
/*
|
||||
Concept: concept_size
|
||||
|
||||
|
||||
template<class T>
|
||||
struct range
|
||||
{
|
||||
|
@ -53,7 +53,7 @@ struct concept_size
|
|||
|
||||
/*
|
||||
Concept: concept_slice
|
||||
|
||||
|
||||
template<class T>
|
||||
struct range
|
||||
{
|
||||
|
@ -67,7 +67,7 @@ struct concept_slice
|
|||
|
||||
/*
|
||||
Concept: concept_sorted
|
||||
|
||||
|
||||
template<class T>
|
||||
struct range
|
||||
{
|
||||
|
@ -82,13 +82,13 @@ struct concept_sorted
|
|||
/*
|
||||
Concept: concept_forwarditeration
|
||||
Checks for the front and pop_front methods
|
||||
|
||||
|
||||
template<class T>
|
||||
struct range
|
||||
{
|
||||
void pop_front();
|
||||
T &front() const;
|
||||
};
|
||||
};
|
||||
*/
|
||||
struct concept_forwarditeration
|
||||
{
|
||||
|
@ -98,13 +98,13 @@ struct concept_forwarditeration
|
|||
/*
|
||||
Concept: concept_backwarditeration
|
||||
Checks for the back and pop_back methods
|
||||
|
||||
|
||||
template<class T>
|
||||
struct range
|
||||
{
|
||||
void pop_back();
|
||||
T &back() const;
|
||||
};
|
||||
};
|
||||
*/
|
||||
struct concept_backwarditeration
|
||||
{
|
||||
|
@ -119,7 +119,7 @@ struct concept_backwarditeration
|
|||
|
||||
/*
|
||||
Class: plain_range
|
||||
|
||||
|
||||
Concepts:
|
||||
<concept_empty>
|
||||
<concept_index>
|
||||
|
@ -142,13 +142,13 @@ public:
|
|||
{
|
||||
*this = r;
|
||||
}
|
||||
|
||||
|
||||
plain_range(T *b, T *e)
|
||||
{
|
||||
begin = b;
|
||||
end = e;
|
||||
}
|
||||
|
||||
|
||||
bool empty() const { return begin >= end; }
|
||||
void pop_front() { assert(!empty()); begin++; }
|
||||
void pop_back() { assert(!empty()); end--; }
|
||||
|
@ -160,7 +160,7 @@ public:
|
|||
{
|
||||
return plain_range(begin+startindex, begin+endindex);
|
||||
}
|
||||
|
||||
|
||||
protected:
|
||||
T *begin;
|
||||
T *end;
|
||||
|
@ -168,7 +168,7 @@ protected:
|
|||
|
||||
/*
|
||||
Class: plain_range_sorted
|
||||
|
||||
|
||||
Concepts:
|
||||
Same as <plain_range> but with these additions:
|
||||
<concept_sorted>
|
||||
|
@ -180,7 +180,7 @@ class plain_range_sorted : public plain_range<T>
|
|||
public:
|
||||
/* sorted concept */
|
||||
void sorted() const { }
|
||||
|
||||
|
||||
plain_range_sorted()
|
||||
{}
|
||||
|
||||
|
@ -188,11 +188,11 @@ public:
|
|||
{
|
||||
*this = r;
|
||||
}
|
||||
|
||||
|
||||
plain_range_sorted(T *b, T *e)
|
||||
: parent(b, e)
|
||||
{}
|
||||
|
||||
|
||||
plain_range_sorted slice(unsigned start, unsigned count)
|
||||
{
|
||||
return plain_range_sorted(parent::begin+start, parent::begin+start+count);
|
||||
|
@ -206,29 +206,29 @@ private:
|
|||
reverse_range() {}
|
||||
public:
|
||||
typedef typename R::type type;
|
||||
|
||||
|
||||
reverse_range(R r)
|
||||
{
|
||||
range = r;
|
||||
}
|
||||
|
||||
|
||||
reverse_range(const reverse_range &other) { range = other.range; }
|
||||
|
||||
|
||||
|
||||
bool empty() const { return range.empty(); }
|
||||
void pop_front() { range.pop_back(); }
|
||||
void pop_back() { range.pop_front(); }
|
||||
type& front() { return range.back(); }
|
||||
type& back() { return range.front(); }
|
||||
|
||||
|
||||
R range;
|
||||
};
|
||||
|
||||
template<class R> reverse_range<R> reverse(R range) {
|
||||
return reverse_range<R>(range);
|
||||
return reverse_range<R>(range);
|
||||
}
|
||||
template<class R> R reverse(reverse_range<R> range) {
|
||||
return range.range;
|
||||
return range.range;
|
||||
}
|
||||
|
||||
#endif // TL_FILE_RANGE_HPP
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
|
||||
/* If you are missing that file, acquire a complete release at teeworlds.com. */
|
||||
#ifndef TL_FILE_SORTED_ARRAY_HPP
|
||||
#define TL_FILE_SORTED_ARRAY_HPP
|
||||
#ifndef BASE_TL_SORTED_ARRAY_H
|
||||
#define BASE_TL_SORTED_ARRAY_H
|
||||
|
||||
#include "algorithm.h"
|
||||
#include "array.h"
|
||||
|
@ -10,11 +10,11 @@ template <class T, class ALLOCATOR = allocator_default<T> >
|
|||
class sorted_array : public array<T, ALLOCATOR>
|
||||
{
|
||||
typedef array<T, ALLOCATOR> parent;
|
||||
|
||||
|
||||
// insert and size is not allowed
|
||||
int insert(const T& item, typename parent::range r) { dbg_break(); return 0; }
|
||||
int set_size(int new_size) { dbg_break(); return 0; }
|
||||
|
||||
|
||||
public:
|
||||
typedef plain_range_sorted<T> range;
|
||||
|
||||
|
@ -27,7 +27,7 @@ public:
|
|||
{
|
||||
return parent::add(item);
|
||||
}
|
||||
|
||||
|
||||
void sort_range()
|
||||
{
|
||||
sort(all());
|
||||
|
@ -37,7 +37,7 @@ public:
|
|||
/*
|
||||
Function: all
|
||||
Returns a sorted range that contains the whole array.
|
||||
*/
|
||||
*/
|
||||
range all() { return range(parent::list, parent::list+parent::num_elements); }
|
||||
};
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
|
||||
/* If you are missing that file, acquire a complete release at teeworlds.com. */
|
||||
#ifndef TL_FILE_STRING_HPP
|
||||
#define TL_FILE_STRING_HPP
|
||||
#ifndef BASE_TL_STRING_H
|
||||
#define BASE_TL_STRING_H
|
||||
|
||||
#include "base.h"
|
||||
#include "allocator.h"
|
||||
|
@ -11,38 +11,38 @@ class string_base : private ALLOCATOR
|
|||
{
|
||||
char *str;
|
||||
int length;
|
||||
|
||||
|
||||
void reset()
|
||||
{
|
||||
str = 0; length = 0;
|
||||
}
|
||||
|
||||
|
||||
void free()
|
||||
{
|
||||
ALLOCATOR::free_array(str);
|
||||
reset();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void copy(const char *other_str, int other_length)
|
||||
{
|
||||
length = other_length;
|
||||
str = ALLOCATOR::alloc_array(length+1);
|
||||
mem_copy(str, other_str, length+1);
|
||||
}
|
||||
|
||||
|
||||
void copy(const string_base &other)
|
||||
{
|
||||
if(!other.str)
|
||||
return;
|
||||
copy(other.str, other.length);
|
||||
}
|
||||
|
||||
|
||||
public:
|
||||
string_base() { reset(); }
|
||||
string_base(const char *other_str) { copy(other_str, str_length(other_str)); }
|
||||
string_base(const string_base &other) { reset(); copy(other); }
|
||||
~string_base() { free(); }
|
||||
|
||||
|
||||
string_base &operator = (const char *other)
|
||||
{
|
||||
free();
|
||||
|
@ -50,17 +50,17 @@ public:
|
|||
copy(other, str_length(other));
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
string_base &operator = (const string_base &other)
|
||||
{
|
||||
free();
|
||||
copy(other);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
bool operator < (const char *other_str) const { return str_comp(str, other_str) < 0; }
|
||||
operator const char *() const { return str; }
|
||||
|
||||
|
||||
const char *cstr() const { return str; }
|
||||
};
|
||||
|
||||
|
|
|
@ -13,19 +13,19 @@ class vector2_base
|
|||
public:
|
||||
union { T x,u; };
|
||||
union { T y,v; };
|
||||
|
||||
|
||||
vector2_base() {}
|
||||
vector2_base(float nx, float ny)
|
||||
{
|
||||
x = nx;
|
||||
y = ny;
|
||||
}
|
||||
|
||||
|
||||
vector2_base operator -() const { return vector2_base(-x, -y); }
|
||||
vector2_base operator -(const vector2_base &v) const { return vector2_base(x-v.x, y-v.y); }
|
||||
vector2_base operator +(const vector2_base &v) const { return vector2_base(x+v.x, y+v.y); }
|
||||
vector2_base operator *(const T v) const { return vector2_base(x*v, y*v); }
|
||||
|
||||
|
||||
const vector2_base &operator =(const vector2_base &v) { x = v.x; y = v.y; return *this; }
|
||||
|
||||
const vector2_base &operator +=(const vector2_base &v) { x += v.x; y += v.y; return *this; }
|
||||
|
@ -81,7 +81,7 @@ inline vector2_base<T> closest_point_on_line(vector2_base<T> line_point0, vector
|
|||
if (t > 1.0f) return 1.0f;
|
||||
return t;*/
|
||||
}
|
||||
|
||||
|
||||
// ------------------------------------
|
||||
template<typename T>
|
||||
class vector3_base
|
||||
|
@ -98,7 +98,7 @@ public:
|
|||
y = ny;
|
||||
z = nz;
|
||||
}
|
||||
|
||||
|
||||
const vector3_base &operator =(const vector3_base &v) { x = v.x; y = v.y; z = v.z; return *this; }
|
||||
|
||||
vector3_base operator -(const vector3_base &v) const { return vector3_base(x-v.x, y-v.y, z-v.z); }
|
||||
|
@ -107,7 +107,7 @@ public:
|
|||
vector3_base operator *(const T v) const { return vector3_base(x*v, y*v, z*v); }
|
||||
vector3_base operator *(const vector3_base &v) const { return vector3_base(x*v.x, y*v.y, z*v.z); }
|
||||
vector3_base operator /(const T v) const { return vector3_base(x/v, y/v, z/v); }
|
||||
|
||||
|
||||
const vector3_base &operator +=(const vector3_base &v) { x += v.x; y += v.y; z += v.z; return *this; }
|
||||
const vector3_base &operator -=(const vector3_base &v) { x -= v.x; y -= v.y; z -= v.z; return *this; }
|
||||
const vector3_base &operator *=(const T v) { x *= v; y *= v; z *= v; return *this; }
|
||||
|
@ -174,13 +174,13 @@ public:
|
|||
z = nz;
|
||||
w = nw;
|
||||
}
|
||||
|
||||
|
||||
vector4_base operator +(const vector4_base &v) const { return vector4_base(x+v.x, y+v.y, z+v.z, w+v.w); }
|
||||
vector4_base operator -(const vector4_base &v) const { return vector4_base(x-v.x, y-v.y, z-v.z, w-v.w); }
|
||||
vector4_base operator -() const { return vector4_base(-x, -y, -z, -w); }
|
||||
vector4_base operator *(const vector4_base &v) const { return vector4_base(x*v.x, y*v.y, z*v.z, w*v.w); }
|
||||
vector4_base operator *(const T v) const { return vector4_base(x*v, y*v, z*v, w*v); }
|
||||
|
||||
|
||||
const vector4_base &operator =(const vector4_base &v) { x = v.x; y = v.y; z = v.z; w = v.w; return *this; }
|
||||
|
||||
const vector4_base &operator +=(const vector4_base &v) { x += v.x; y += v.y; z += v.z; w += v.w; return *this; }
|
||||
|
|
|
@ -18,13 +18,13 @@ protected:
|
|||
int m_CurGameTick;
|
||||
float m_GameIntraTick;
|
||||
float m_GameTickTime;
|
||||
|
||||
|
||||
int m_PredTick;
|
||||
float m_PredIntraTick;
|
||||
|
||||
|
||||
float m_LocalTime;
|
||||
float m_FrameTime;
|
||||
|
||||
|
||||
int m_GameTickSpeed;
|
||||
public:
|
||||
|
||||
|
@ -66,11 +66,11 @@ public:
|
|||
inline float PredIntraGameTick() const { return m_PredIntraTick; }
|
||||
inline float GameTickTime() const { return m_GameTickTime; }
|
||||
inline int GameTickSpeed() const { return m_GameTickSpeed; }
|
||||
|
||||
|
||||
// other time access
|
||||
inline float FrameTime() const { return m_FrameTime; }
|
||||
inline float LocalTime() const { return m_LocalTime; }
|
||||
|
||||
|
||||
// actions
|
||||
virtual void Connect(const char *pAddress) = 0;
|
||||
virtual void Disconnect() = 0;
|
||||
|
@ -88,26 +88,26 @@ public:
|
|||
//
|
||||
virtual int MapDownloadAmount() = 0;
|
||||
virtual int MapDownloadTotalsize() = 0;
|
||||
|
||||
|
||||
// input
|
||||
virtual int *GetInput(int Tick) = 0;
|
||||
|
||||
|
||||
// remote console
|
||||
virtual void RconAuth(const char *pUsername, const char *pPassword) = 0;
|
||||
virtual bool RconAuthed() = 0;
|
||||
virtual void Rcon(const char *pLine) = 0;
|
||||
|
||||
|
||||
// server info
|
||||
virtual void GetServerInfo(class CServerInfo *pServerInfo) = 0;
|
||||
|
||||
|
||||
// snapshot interface
|
||||
|
||||
|
||||
enum
|
||||
{
|
||||
SNAP_CURRENT=0,
|
||||
SNAP_PREV=1
|
||||
};
|
||||
|
||||
|
||||
// TODO: Refactor: should redo this a bit i think, too many virtual calls
|
||||
virtual int SnapNumItems(int SnapID) = 0;
|
||||
virtual void *SnapFindItem(int SnapID, int Type, int ID) = 0;
|
||||
|
@ -126,8 +126,8 @@ public:
|
|||
return -1;
|
||||
return SendMsg(&Packer, Flags);
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
//
|
||||
virtual const char *ErrorString() = 0;
|
||||
virtual const char *LatestVersion() = 0;
|
||||
virtual bool ConnectionProblems() = 0;
|
||||
|
@ -163,9 +163,9 @@ public:
|
|||
virtual void OnMessage(int MsgID, CUnpacker *pUnpacker) = 0;
|
||||
virtual void OnPredict() = 0;
|
||||
virtual void OnActivateEditor() = 0;
|
||||
|
||||
|
||||
virtual int OnSnapInput(int *pData) = 0;
|
||||
|
||||
|
||||
virtual const char *GetItemName(int Type) = 0;
|
||||
virtual int GetCountryIndex(int Code) = 0;
|
||||
virtual const char *Version() = 0;
|
||||
|
|
|
@ -545,7 +545,7 @@ void CClient::RconAuth(const char *pName, const char *pPassword)
|
|||
{
|
||||
if(RconAuthed())
|
||||
return;
|
||||
|
||||
|
||||
CMsgPacker Msg(NETMSG_RCON_AUTH);
|
||||
Msg.AddString(pName, 32);
|
||||
Msg.AddString(pPassword, 32);
|
||||
|
@ -860,7 +860,7 @@ void CClient::DebugRender()
|
|||
total = 42
|
||||
*/
|
||||
FrameTimeAvg = FrameTimeAvg*0.9f + m_FrameTime*0.1f;
|
||||
str_format(aBuffer, sizeof(aBuffer), "ticks: %8d %8d mem %dk %d gfxmem: %dk fps: %3d",
|
||||
str_format(aBuffer, sizeof(aBuffer), "ticks: %8d %8d mem %dk %d gfxmem: %dk fps: %3d",
|
||||
m_CurGameTick, m_PredTick,
|
||||
mem_stats()->allocated/1024,
|
||||
mem_stats()->total_allocations,
|
||||
|
@ -1033,7 +1033,7 @@ void CClient::ProcessConnlessPacket(CNetChunk *pPacket)
|
|||
// version info
|
||||
if(pPacket->m_DataSize == (int)(sizeof(VERSIONSRV_VERSION) + sizeof(VERSION_DATA)) &&
|
||||
mem_comp(pPacket->m_pData, VERSIONSRV_VERSION, sizeof(VERSIONSRV_VERSION)) == 0)
|
||||
|
||||
|
||||
{
|
||||
unsigned char *pVersionData = (unsigned char*)pPacket->m_pData + sizeof(VERSIONSRV_VERSION);
|
||||
int VersionMatch = !mem_comp(pVersionData, VERSION_DATA, sizeof(VERSION_DATA));
|
||||
|
@ -1063,7 +1063,7 @@ void CClient::ProcessConnlessPacket(CNetChunk *pPacket)
|
|||
|
||||
// map version list
|
||||
if(pPacket->m_DataSize >= (int)sizeof(VERSIONSRV_MAPLIST) &&
|
||||
mem_comp(pPacket->m_pData, VERSIONSRV_MAPLIST, sizeof(VERSIONSRV_MAPLIST)) == 0)
|
||||
mem_comp(pPacket->m_pData, VERSIONSRV_MAPLIST, sizeof(VERSIONSRV_MAPLIST)) == 0)
|
||||
{
|
||||
int Size = pPacket->m_DataSize-sizeof(VERSIONSRV_MAPLIST);
|
||||
int Num = Size/sizeof(CMapVersion);
|
||||
|
@ -1117,7 +1117,7 @@ void CClient::ProcessConnlessPacket(CNetChunk *pPacket)
|
|||
mem_copy(Addr.ip, pAddrs[i].m_aIp, sizeof(Addr.ip));
|
||||
}
|
||||
Addr.port = (pAddrs[i].m_aPort[0]<<8) | pAddrs[i].m_aPort[1];
|
||||
|
||||
|
||||
m_ServerBrowser.Set(Addr, IServerBrowser::SET_MASTER_ADD, -1, 0x0);
|
||||
}
|
||||
}
|
||||
|
@ -1128,7 +1128,7 @@ void CClient::ProcessConnlessPacket(CNetChunk *pPacket)
|
|||
// we got ze info
|
||||
CUnpacker Up;
|
||||
CServerInfo Info = {0};
|
||||
|
||||
|
||||
Up.Reset((unsigned char*)pPacket->m_pData+sizeof(SERVERBROWSE_INFO), pPacket->m_DataSize-sizeof(SERVERBROWSE_INFO));
|
||||
int Token = str_toint(Up.GetString());
|
||||
str_copy(Info.m_aVersion, Up.GetString(CUnpacker::SANITIZE_CC|CUnpacker::SKIP_START_WHITESPACES), sizeof(Info.m_aVersion));
|
||||
|
@ -1285,7 +1285,7 @@ void CClient::ProcessServerPacket(CNetChunk *pPacket)
|
|||
if(!pError)
|
||||
{
|
||||
m_pConsole->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "client/network", "loading done");
|
||||
SendReady();
|
||||
SendReady();
|
||||
}
|
||||
else
|
||||
DisconnectWithReason(pError);
|
||||
|
|
|
@ -14,14 +14,14 @@ class CFriends : public IFriends
|
|||
static void ConRemoveFriend(IConsole::IResult *pResult, void *pUserData, int ClientID);
|
||||
|
||||
static void ConfigSaveCallback(IConfig *pConfig, void *pUserData);
|
||||
|
||||
|
||||
public:
|
||||
CFriends();
|
||||
|
||||
|
||||
void Init();
|
||||
|
||||
|
||||
int NumFriends() const { return m_NumFriends; }
|
||||
const CFriendInfo *GetFriend(int Index) const;
|
||||
const CFriendInfo *GetFriend(int Index) const;
|
||||
bool IsFriend(const char *pName, const char *pClan, bool PlayersOnly) const;
|
||||
|
||||
void AddFriend(const char *pName, const char *pClan);
|
||||
|
|
|
@ -50,7 +50,7 @@ static CVideoMode g_aFakeModes[] = {
|
|||
{1800,1440,8,8,8}, {1856,1392,8,8,8}, {1920,1080,8,8,8},
|
||||
{1920,1200,8,8,8}, {1920,1440,8,8,8}, {1920,2400,8,8,8},
|
||||
{2048,1536,8,8,8},
|
||||
|
||||
|
||||
{320,240,5,6,5}, {400,300,5,6,5}, {640,480,5,6,5},
|
||||
{720,400,5,6,5}, {768,576,5,6,5}, {800,600,5,6,5},
|
||||
{1024,600,5,6,5}, {1024,768,5,6,5}, {1152,864,5,6,5},
|
||||
|
@ -67,7 +67,7 @@ void CGraphics_OpenGL::Flush()
|
|||
{
|
||||
if(m_NumVertices == 0)
|
||||
return;
|
||||
|
||||
|
||||
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
|
||||
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
|
||||
|
@ -83,7 +83,7 @@ void CGraphics_OpenGL::Flush()
|
|||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
glEnableClientState(GL_COLOR_ARRAY);
|
||||
|
||||
|
||||
if(m_RenderEnable)
|
||||
{
|
||||
if(m_Drawing == DRAWING_QUADS)
|
||||
|
@ -91,7 +91,7 @@ void CGraphics_OpenGL::Flush()
|
|||
else if(m_Drawing == DRAWING_LINES)
|
||||
glDrawArrays(GL_LINES, 0, m_NumVertices);
|
||||
}
|
||||
|
||||
|
||||
// Reset pointer
|
||||
m_NumVertices = 0;
|
||||
}
|
||||
|
@ -125,26 +125,26 @@ unsigned char CGraphics_OpenGL::Sample(int w, int h, const unsigned char *pData,
|
|||
pData[(v*w+u+1)*4+Offset]+
|
||||
pData[((v+1)*w+u)*4+Offset]+
|
||||
pData[((v+1)*w+u+1)*4+Offset])/4;
|
||||
}
|
||||
}
|
||||
|
||||
CGraphics_OpenGL::CGraphics_OpenGL()
|
||||
{
|
||||
m_NumVertices = 0;
|
||||
|
||||
|
||||
m_ScreenX0 = 0;
|
||||
m_ScreenY0 = 0;
|
||||
m_ScreenX1 = 0;
|
||||
m_ScreenY1 = 0;
|
||||
|
||||
|
||||
m_ScreenWidth = -1;
|
||||
m_ScreenHeight = -1;
|
||||
|
||||
|
||||
m_Rotation = 0;
|
||||
m_Drawing = 0;
|
||||
m_InvalidTexture = 0;
|
||||
|
||||
|
||||
m_TextureMemoryUsage = 0;
|
||||
|
||||
|
||||
m_RenderEnable = true;
|
||||
m_DoScreenshot = false;
|
||||
}
|
||||
|
@ -161,7 +161,7 @@ void CGraphics_OpenGL::ClipDisable()
|
|||
//if(no_gfx) return;
|
||||
glDisable(GL_SCISSOR_TEST);
|
||||
}
|
||||
|
||||
|
||||
void CGraphics_OpenGL::BlendNone()
|
||||
{
|
||||
glDisable(GL_BLEND);
|
||||
|
@ -180,10 +180,10 @@ void CGraphics_OpenGL::BlendAdditive()
|
|||
}
|
||||
|
||||
int CGraphics_OpenGL::MemoryUsage() const
|
||||
{
|
||||
{
|
||||
return m_TextureMemoryUsage;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void CGraphics_OpenGL::MapScreen(float TopLeftX, float TopLeftY, float BottomRightX, float BottomRightY)
|
||||
{
|
||||
m_ScreenX0 = TopLeftX;
|
||||
|
@ -220,7 +220,7 @@ void CGraphics_OpenGL::LinesEnd()
|
|||
void CGraphics_OpenGL::LinesDraw(const CLineItem *pArray, int Num)
|
||||
{
|
||||
dbg_assert(m_Drawing == DRAWING_LINES, "called draw without begin");
|
||||
|
||||
|
||||
for(int i = 0; i < Num; ++i)
|
||||
{
|
||||
m_aVertices[m_NumVertices + 2*i].m_Pos.x = pArray[i].m_X0;
|
||||
|
@ -241,10 +241,10 @@ int CGraphics_OpenGL::UnloadTexture(int Index)
|
|||
{
|
||||
if(Index == m_InvalidTexture)
|
||||
return 0;
|
||||
|
||||
|
||||
if(Index < 0)
|
||||
return 0;
|
||||
|
||||
|
||||
glDeleteTextures(1, &m_aTextures[Index].m_Tex);
|
||||
m_aTextures[Index].m_Next = m_FirstFreeTexture;
|
||||
m_TextureMemoryUsage -= m_aTextures[Index].m_MemSize;
|
||||
|
@ -261,16 +261,16 @@ int CGraphics_OpenGL::LoadTextureRaw(int Width, int Height, int Format, const vo
|
|||
int Oglformat = 0;
|
||||
int StoreOglformat = 0;
|
||||
int Tex = 0;
|
||||
|
||||
|
||||
// don't waste memory on texture if we are stress testing
|
||||
if(g_Config.m_DbgStress)
|
||||
return m_InvalidTexture;
|
||||
|
||||
|
||||
// grab texture
|
||||
Tex = m_FirstFreeTexture;
|
||||
m_FirstFreeTexture = m_aTextures[Tex].m_Next;
|
||||
m_aTextures[Tex].m_Next = -1;
|
||||
|
||||
|
||||
// resample if needed
|
||||
if(!(Flags&TEXLOAD_NORESAMPLE) && g_Config.m_GfxTextureQuality==0)
|
||||
{
|
||||
|
@ -296,13 +296,13 @@ int CGraphics_OpenGL::LoadTextureRaw(int Width, int Height, int Format, const vo
|
|||
pTexData = pTmpData;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Oglformat = GL_RGBA;
|
||||
if(Format == CImageInfo::FORMAT_RGB)
|
||||
Oglformat = GL_RGB;
|
||||
else if(Format == CImageInfo::FORMAT_ALPHA)
|
||||
Oglformat = GL_ALPHA;
|
||||
|
||||
|
||||
// upload texture
|
||||
if(g_Config.m_GfxTextureCompression)
|
||||
{
|
||||
|
@ -320,13 +320,13 @@ int CGraphics_OpenGL::LoadTextureRaw(int Width, int Height, int Format, const vo
|
|||
else if(StoreFormat == CImageInfo::FORMAT_ALPHA)
|
||||
StoreOglformat = GL_ALPHA;
|
||||
}
|
||||
|
||||
|
||||
glGenTextures(1, &m_aTextures[Tex].m_Tex);
|
||||
glBindTexture(GL_TEXTURE_2D, m_aTextures[Tex].m_Tex);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
|
||||
gluBuild2DMipmaps(GL_TEXTURE_2D, StoreOglformat, Width, Height, Oglformat, GL_UNSIGNED_BYTE, pTexData);
|
||||
|
||||
|
||||
// calculate memory usage
|
||||
{
|
||||
int PixelSize = 4;
|
||||
|
@ -346,7 +346,7 @@ int CGraphics_OpenGL::LoadTextureRaw(int Width, int Height, int Format, const vo
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
m_TextureMemoryUsage += m_aTextures[Tex].m_MemSize;
|
||||
mem_free(pTmpData);
|
||||
return Tex;
|
||||
|
@ -358,7 +358,7 @@ int CGraphics_OpenGL::LoadTexture(const char *pFilename, int StorageType, int St
|
|||
int l = str_length(pFilename);
|
||||
int ID;
|
||||
CImageInfo Img;
|
||||
|
||||
|
||||
if(l < 3)
|
||||
return -1;
|
||||
if(LoadPNG(&Img, pFilename, StorageType))
|
||||
|
@ -370,7 +370,7 @@ int CGraphics_OpenGL::LoadTexture(const char *pFilename, int StorageType, int St
|
|||
mem_free(Img.m_pData);
|
||||
return ID;
|
||||
}
|
||||
|
||||
|
||||
return m_InvalidTexture;
|
||||
}
|
||||
|
||||
|
@ -379,7 +379,7 @@ int CGraphics_OpenGL::LoadPNG(CImageInfo *pImg, const char *pFilename, int Stora
|
|||
char aCompleteFilename[512];
|
||||
unsigned char *pBuffer;
|
||||
png_t Png; // ignore_convention
|
||||
|
||||
|
||||
// open file for reading
|
||||
png_init(0,0); // ignore_convention
|
||||
|
||||
|
@ -391,7 +391,7 @@ int CGraphics_OpenGL::LoadPNG(CImageInfo *pImg, const char *pFilename, int Stora
|
|||
dbg_msg("game/png", "failed to open file. filename='%s'", pFilename);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int Error = png_open_file(&Png, aCompleteFilename); // ignore_convention
|
||||
if(Error != PNG_NO_ERROR)
|
||||
{
|
||||
|
@ -400,18 +400,18 @@ int CGraphics_OpenGL::LoadPNG(CImageInfo *pImg, const char *pFilename, int Stora
|
|||
png_close_file(&Png); // ignore_convention
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
if(Png.depth != 8 || (Png.color_type != PNG_TRUECOLOR && Png.color_type != PNG_TRUECOLOR_ALPHA)) // ignore_convention
|
||||
{
|
||||
dbg_msg("game/png", "invalid format. filename='%s'", aCompleteFilename);
|
||||
png_close_file(&Png); // ignore_convention
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
pBuffer = (unsigned char *)mem_alloc(Png.width * Png.height * Png.bpp, 1); // ignore_convention
|
||||
png_get_data(&Png, pBuffer); // ignore_convention
|
||||
png_close_file(&Png); // ignore_convention
|
||||
|
||||
|
||||
pImg->m_Width = Png.width; // ignore_convention
|
||||
pImg->m_Height = Png.height; // ignore_convention
|
||||
if(Png.color_type == PNG_TRUECOLOR) // ignore_convention
|
||||
|
@ -435,7 +435,7 @@ void CGraphics_OpenGL::ScreenshotDirect(const char *pFilename)
|
|||
glPixelStorei(GL_PACK_ALIGNMENT, 1);
|
||||
glReadPixels(0,0, w, h, GL_RGB, GL_UNSIGNED_BYTE, pPixelData);
|
||||
glPixelStorei(GL_PACK_ALIGNMENT, Alignment);
|
||||
|
||||
|
||||
// flip the pixel because opengl works from bottom left corner
|
||||
for(y = 0; y < h/2; y++)
|
||||
{
|
||||
|
@ -443,16 +443,16 @@ void CGraphics_OpenGL::ScreenshotDirect(const char *pFilename)
|
|||
mem_copy(pPixelData+y*w*3, pPixelData+(h-y-1)*w*3, w*3);
|
||||
mem_copy(pPixelData+(h-y-1)*w*3, pTempRow,w*3);
|
||||
}
|
||||
|
||||
|
||||
// find filename
|
||||
{
|
||||
char aWholePath[1024];
|
||||
png_t Png; // ignore_convention
|
||||
|
||||
IOHANDLE File = m_pStorage->OpenFile(pFilename, IOFLAG_WRITE, IStorage::TYPE_SAVE, aWholePath, sizeof(aWholePath));
|
||||
IOHANDLE File = m_pStorage->OpenFile(pFilename, IOFLAG_WRITE, IStorage::TYPE_SAVE, aWholePath, sizeof(aWholePath));
|
||||
if(File)
|
||||
io_close(File);
|
||||
|
||||
|
||||
// save png
|
||||
char aBuf[256];
|
||||
str_format(aBuf, sizeof(aBuf), "saved screenshot to '%s'", aWholePath);
|
||||
|
@ -490,7 +490,7 @@ void CGraphics_OpenGL::QuadsBegin()
|
|||
{
|
||||
dbg_assert(m_Drawing == 0, "called quads_begin twice");
|
||||
m_Drawing = DRAWING_QUADS;
|
||||
|
||||
|
||||
QuadsSetSubset(0,0,1,1);
|
||||
QuadsSetRotation(0);
|
||||
SetColor(1,1,1,1);
|
||||
|
@ -609,7 +609,7 @@ void CGraphics_OpenGL::QuadsDrawTL(const CQuadItem *pArray, int Num)
|
|||
void CGraphics_OpenGL::QuadsDrawFreeform(const CFreeformItem *pArray, int Num)
|
||||
{
|
||||
dbg_assert(m_Drawing == DRAWING_QUADS, "called quads_draw_freeform without begin");
|
||||
|
||||
|
||||
for(int i = 0; i < Num; ++i)
|
||||
{
|
||||
m_aVertices[m_NumVertices + 4*i].m_Pos.x = pArray[i].m_X0;
|
||||
|
@ -632,7 +632,7 @@ void CGraphics_OpenGL::QuadsDrawFreeform(const CFreeformItem *pArray, int Num)
|
|||
m_aVertices[m_NumVertices + 4*i + 3].m_Tex = m_aTexture[2];
|
||||
m_aVertices[m_NumVertices + 4*i + 3].m_Color = m_aColor[2];
|
||||
}
|
||||
|
||||
|
||||
AddVertices(4*Num);
|
||||
}
|
||||
|
||||
|
@ -647,7 +647,7 @@ void CGraphics_OpenGL::QuadsText(float x, float y, float Size, float r, float g,
|
|||
{
|
||||
char c = *pText;
|
||||
pText++;
|
||||
|
||||
|
||||
if(c == '\n')
|
||||
{
|
||||
x = StartX;
|
||||
|
@ -660,13 +660,13 @@ void CGraphics_OpenGL::QuadsText(float x, float y, float Size, float r, float g,
|
|||
(c/16)/16.0f,
|
||||
(c%16)/16.0f+1.0f/16.0f,
|
||||
(c/16)/16.0f+1.0f/16.0f);
|
||||
|
||||
|
||||
CQuadItem QuadItem(x, y, Size, Size);
|
||||
QuadsDrawTL(&QuadItem, 1);
|
||||
x += Size/2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
QuadsEnd();
|
||||
}
|
||||
|
||||
|
@ -674,7 +674,7 @@ bool CGraphics_OpenGL::Init()
|
|||
{
|
||||
m_pStorage = Kernel()->RequestInterface<IStorage>();
|
||||
m_pConsole = Kernel()->RequestInterface<IConsole>();
|
||||
|
||||
|
||||
// Set all z to -5.0f
|
||||
for(int i = 0; i < MAX_VERTICES; i++)
|
||||
m_aVertices[i].m_Pos.z = -5.0f;
|
||||
|
@ -691,21 +691,21 @@ bool CGraphics_OpenGL::Init()
|
|||
glDisable(GL_DEPTH_TEST);
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
|
||||
|
||||
glAlphaFunc(GL_GREATER, 0);
|
||||
glEnable(GL_ALPHA_TEST);
|
||||
glDepthMask(0);
|
||||
|
||||
// create null texture, will get id=0
|
||||
static const unsigned char aNullTextureData[] = {
|
||||
0xff,0x00,0x00,0xff, 0xff,0x00,0x00,0xff, 0x00,0xff,0x00,0xff, 0x00,0xff,0x00,0xff,
|
||||
0xff,0x00,0x00,0xff, 0xff,0x00,0x00,0xff, 0x00,0xff,0x00,0xff, 0x00,0xff,0x00,0xff,
|
||||
0x00,0x00,0xff,0xff, 0x00,0x00,0xff,0xff, 0xff,0xff,0x00,0xff, 0xff,0xff,0x00,0xff,
|
||||
0x00,0x00,0xff,0xff, 0x00,0x00,0xff,0xff, 0xff,0xff,0x00,0xff, 0xff,0xff,0x00,0xff,
|
||||
0xff,0x00,0x00,0xff, 0xff,0x00,0x00,0xff, 0x00,0xff,0x00,0xff, 0x00,0xff,0x00,0xff,
|
||||
0xff,0x00,0x00,0xff, 0xff,0x00,0x00,0xff, 0x00,0xff,0x00,0xff, 0x00,0xff,0x00,0xff,
|
||||
0x00,0x00,0xff,0xff, 0x00,0x00,0xff,0xff, 0xff,0xff,0x00,0xff, 0xff,0xff,0x00,0xff,
|
||||
0x00,0x00,0xff,0xff, 0x00,0x00,0xff,0xff, 0xff,0xff,0x00,0xff, 0xff,0xff,0x00,0xff,
|
||||
};
|
||||
|
||||
|
||||
m_InvalidTexture = LoadTextureRaw(4,4,CImageInfo::FORMAT_RGBA,aNullTextureData,CImageInfo::FORMAT_RGBA,TEXLOAD_NORESAMPLE);
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -713,7 +713,7 @@ int CGraphics_SDL::TryInit()
|
|||
{
|
||||
const SDL_VideoInfo *pInfo;
|
||||
int Flags = SDL_OPENGL;
|
||||
|
||||
|
||||
m_ScreenWidth = g_Config.m_GfxScreenWidth;
|
||||
m_ScreenHeight = g_Config.m_GfxScreenHeight;
|
||||
|
||||
|
@ -721,7 +721,7 @@ int CGraphics_SDL::TryInit()
|
|||
SDL_EventState(SDL_MOUSEMOTION, SDL_IGNORE);
|
||||
|
||||
// set flags
|
||||
Flags = SDL_OPENGL;
|
||||
Flags = SDL_OPENGL;
|
||||
Flags |= SDL_GL_DOUBLEBUFFER;
|
||||
Flags |= SDL_HWPALETTE;
|
||||
if(g_Config.m_DbgResizable)
|
||||
|
@ -755,7 +755,7 @@ int CGraphics_SDL::TryInit()
|
|||
|
||||
// set caption
|
||||
SDL_WM_SetCaption("Teeworlds", "Teeworlds");
|
||||
|
||||
|
||||
// create window
|
||||
m_pScreenSurface = SDL_SetVideoMode(m_ScreenWidth, m_ScreenHeight, 0, Flags);
|
||||
if(m_pScreenSurface == NULL)
|
||||
|
@ -763,7 +763,7 @@ int CGraphics_SDL::TryInit()
|
|||
dbg_msg("gfx", "unable to set video mode: %s", SDL_GetError());
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -772,12 +772,12 @@ int CGraphics_SDL::InitWindow()
|
|||
{
|
||||
if(TryInit() == 0)
|
||||
return 0;
|
||||
|
||||
|
||||
// try disabling fsaa
|
||||
while(g_Config.m_GfxFsaaSamples)
|
||||
{
|
||||
g_Config.m_GfxFsaaSamples--;
|
||||
|
||||
|
||||
if(g_Config.m_GfxFsaaSamples)
|
||||
dbg_msg("gfx", "lowering FSAA to %d and trying again", g_Config.m_GfxFsaaSamples);
|
||||
else
|
||||
|
@ -799,8 +799,8 @@ int CGraphics_SDL::InitWindow()
|
|||
}
|
||||
|
||||
dbg_msg("gfx", "out of ideas. failed to init graphics");
|
||||
|
||||
return -1;
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
|
@ -813,34 +813,34 @@ bool CGraphics_SDL::Init()
|
|||
{
|
||||
{
|
||||
int Systems = SDL_INIT_VIDEO;
|
||||
|
||||
|
||||
if(g_Config.m_SndEnable)
|
||||
Systems |= SDL_INIT_AUDIO;
|
||||
|
||||
if(g_Config.m_ClEventthread)
|
||||
Systems |= SDL_INIT_EVENTTHREAD;
|
||||
|
||||
|
||||
if(SDL_Init(Systems) < 0)
|
||||
{
|
||||
dbg_msg("gfx", "unable to init SDL: %s", SDL_GetError());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
atexit(SDL_Quit); // ignore_convention
|
||||
|
||||
#ifdef CONF_FAMILY_WINDOWS
|
||||
if(!getenv("SDL_VIDEO_WINDOW_POS") && !getenv("SDL_VIDEO_CENTERED")) // ignore_convention
|
||||
putenv("SDL_VIDEO_WINDOW_POS=8,27"); // ignore_convention
|
||||
#endif
|
||||
|
||||
|
||||
if(InitWindow() != 0)
|
||||
return true;
|
||||
|
||||
SDL_ShowCursor(0);
|
||||
|
||||
|
||||
CGraphics_OpenGL::Init();
|
||||
|
||||
|
||||
MapScreen(0,0,g_Config.m_GfxScreenWidth, g_Config.m_GfxScreenHeight);
|
||||
return false;
|
||||
}
|
||||
|
@ -887,11 +887,11 @@ void CGraphics_SDL::Swap()
|
|||
ScreenshotDirect(m_aScreenshotName);
|
||||
m_DoScreenshot = false;
|
||||
}
|
||||
|
||||
|
||||
SDL_GL_SwapBuffers();
|
||||
|
||||
|
||||
if(g_Config.m_GfxFinish)
|
||||
glFinish();
|
||||
glFinish();
|
||||
}
|
||||
|
||||
|
||||
|
@ -908,9 +908,9 @@ int CGraphics_SDL::GetVideoModes(CVideoMode *pModes, int MaxModes)
|
|||
Count = MaxModes;
|
||||
return Count;
|
||||
}
|
||||
|
||||
|
||||
// TODO: fix this code on osx or windows
|
||||
|
||||
|
||||
ppModes = SDL_ListModes(NULL, SDL_OPENGL|SDL_GL_DOUBLEBUFFER|SDL_FULLSCREEN);
|
||||
if(ppModes == NULL)
|
||||
{
|
||||
|
@ -936,7 +936,7 @@ int CGraphics_SDL::GetVideoModes(CVideoMode *pModes, int MaxModes)
|
|||
NumModes++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return NumModes;
|
||||
}
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ class CGraphics_OpenGL : public IEngineGraphics
|
|||
protected:
|
||||
class IStorage *m_pStorage;
|
||||
class IConsole *m_pConsole;
|
||||
|
||||
|
||||
//
|
||||
typedef struct { float x, y, z; } CPoint;
|
||||
typedef struct { float u, v; } CTexCoord;
|
||||
|
@ -20,14 +20,14 @@ protected:
|
|||
CTexCoord m_Tex;
|
||||
CColor m_Color;
|
||||
} CVertex;
|
||||
|
||||
|
||||
enum
|
||||
{
|
||||
MAX_VERTICES = 32*1024,
|
||||
MAX_TEXTURES = 1024*4,
|
||||
|
||||
|
||||
DRAWING_QUADS=1,
|
||||
DRAWING_LINES=2
|
||||
DRAWING_LINES=2
|
||||
};
|
||||
|
||||
CVertex m_aVertices[MAX_VERTICES];
|
||||
|
@ -65,27 +65,27 @@ protected:
|
|||
void Flush();
|
||||
void AddVertices(int Count);
|
||||
void Rotate4(const CPoint &rCenter, CVertex *pPoints);
|
||||
|
||||
|
||||
static unsigned char Sample(int w, int h, const unsigned char *pData, int u, int v, int Offset);
|
||||
public:
|
||||
CGraphics_OpenGL();
|
||||
|
||||
|
||||
virtual void ClipEnable(int x, int y, int w, int h);
|
||||
virtual void ClipDisable();
|
||||
|
||||
|
||||
virtual void BlendNone();
|
||||
virtual void BlendNormal();
|
||||
virtual void BlendAdditive();
|
||||
|
||||
virtual int MemoryUsage() const;
|
||||
|
||||
|
||||
virtual void MapScreen(float TopLeftX, float TopLeftY, float BottomRightX, float BottomRightY);
|
||||
virtual void GetScreen(float *pTopLeftX, float *pTopLeftY, float *pBottomRightX, float *pBottomRightY);
|
||||
|
||||
virtual void LinesBegin();
|
||||
virtual void LinesEnd();
|
||||
virtual void LinesDraw(const CLineItem *pArray, int Num);
|
||||
|
||||
|
||||
virtual int UnloadTexture(int Index);
|
||||
virtual int LoadTextureRaw(int Width, int Height, int Format, const void *pData, int StoreFormat, int Flags);
|
||||
|
||||
|
@ -115,14 +115,14 @@ public:
|
|||
virtual void QuadsDrawTL(const CQuadItem *pArray, int Num);
|
||||
virtual void QuadsDrawFreeform(const CFreeformItem *pArray, int Num);
|
||||
virtual void QuadsText(float x, float y, float Size, float r, float g, float b, float a, const char *pText);
|
||||
|
||||
|
||||
virtual bool Init();
|
||||
};
|
||||
|
||||
class CGraphics_SDL : public CGraphics_OpenGL
|
||||
{
|
||||
SDL_Surface *m_pScreenSurface;
|
||||
|
||||
SDL_Surface *m_pScreenSurface;
|
||||
|
||||
int TryInit();
|
||||
int InitWindow();
|
||||
public:
|
||||
|
@ -141,7 +141,7 @@ public:
|
|||
virtual void Swap();
|
||||
|
||||
virtual int GetVideoModes(CVideoMode *pModes, int MaxModes);
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -154,7 +154,7 @@ int CInput::Update()
|
|||
// skip private use area of the BMP(contains the unicodes for keyboard function keys on MacOS)
|
||||
if(Event.key.keysym.unicode < 0xE000 || Event.key.keysym.unicode > 0xF8FF) // ignore_convention
|
||||
AddEvent(Event.key.keysym.unicode, 0, 0); // ignore_convention
|
||||
Key = Event.key.keysym.sym; // ignore_convention
|
||||
Key = Event.key.keysym.sym; // ignore_convention
|
||||
break;
|
||||
case SDL_KEYUP:
|
||||
Action = IInput::FLAG_RELEASE;
|
||||
|
|
|
@ -86,7 +86,7 @@ bool CServerBrowser::SortCompareName(int Index1, int Index2) const
|
|||
CServerEntry *a = m_ppServerlist[Index1];
|
||||
CServerEntry *b = m_ppServerlist[Index2];
|
||||
// make sure empty entries are listed last
|
||||
return (a->m_GotInfo && b->m_GotInfo) || (!a->m_GotInfo && !b->m_GotInfo) ? str_comp(a->m_Info.m_aName, b->m_Info.m_aName) < 0 :
|
||||
return (a->m_GotInfo && b->m_GotInfo) || (!a->m_GotInfo && !b->m_GotInfo) ? str_comp(a->m_Info.m_aName, b->m_Info.m_aName) < 0 :
|
||||
a->m_GotInfo ? true : false;
|
||||
}
|
||||
|
||||
|
@ -535,7 +535,7 @@ void CServerBrowser::RequestImpl(const NETADDR &Addr, CServerEntry *pEntry) cons
|
|||
Packet.m_Flags = NETSENDFLAG_CONNLESS;
|
||||
Packet.m_DataSize = sizeof(Buffer);
|
||||
Packet.m_pData = Buffer;
|
||||
|
||||
|
||||
m_pNetClient->Send(&Packet);
|
||||
|
||||
if(pEntry)
|
||||
|
@ -659,7 +659,7 @@ void CServerBrowser::AddFavorite(const NETADDR &Addr)
|
|||
if(pEntry)
|
||||
pEntry->m_Info.m_Favorite = 1;
|
||||
|
||||
if(g_Config.m_Debug)
|
||||
if(g_Config.m_Debug)
|
||||
{
|
||||
char aAddrStr[NETADDR_MAXSTRSIZE];
|
||||
net_addr_str(&Addr, aAddrStr, sizeof(aAddrStr));
|
||||
|
@ -705,7 +705,7 @@ int CServerBrowser::LoadingProgression() const
|
|||
{
|
||||
if(m_NumServers == 0)
|
||||
return 0;
|
||||
|
||||
|
||||
int Servers = m_NumServers;
|
||||
int Loaded = m_NumServers-m_NumRequests;
|
||||
return 100.0f * Loaded/Servers;
|
||||
|
|
|
@ -103,7 +103,7 @@ private:
|
|||
|
||||
CServerEntry *Find(const NETADDR &Addr);
|
||||
CServerEntry *Add(const NETADDR &Addr);
|
||||
|
||||
|
||||
void RemoveRequest(CServerEntry *pEntry);
|
||||
void QueueRequest(CServerEntry *pEntry);
|
||||
|
||||
|
|
|
@ -157,8 +157,12 @@ static void Mix(short *pFinalOut, unsigned Frames)
|
|||
|
||||
// free voice if not used any more
|
||||
if(v->m_Tick == v->m_pSample->m_NumFrames)
|
||||
v->m_pSample = 0;
|
||||
|
||||
{
|
||||
if(v->m_Flags&ISound::FLAG_LOOP)
|
||||
v->m_Tick = 0;
|
||||
else
|
||||
v->m_pSample = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -410,7 +414,7 @@ void CSound::SetListenerPos(float x, float y)
|
|||
m_CenterX = (int)x;
|
||||
m_CenterY = (int)y;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void CSound::SetChannel(int ChannelID, float Vol, float Pan)
|
||||
{
|
||||
|
@ -463,11 +467,16 @@ int CSound::Play(int ChannelID, int SampleID, int Flags)
|
|||
return Play(ChannelID, SampleID, Flags, 0, 0);
|
||||
}
|
||||
|
||||
void CSound::Stop(int VoiceID)
|
||||
void CSound::Stop(int SampleID)
|
||||
{
|
||||
// TODO: a nice fade out
|
||||
lock_wait(m_SoundLock);
|
||||
m_aVoices[VoiceID].m_pSample = 0;
|
||||
CSample *pSample = &m_aSamples[SampleID];
|
||||
for(int i = 0; i < NUM_VOICES; i++)
|
||||
{
|
||||
if(m_aVoices[i].m_pSample == pSample)
|
||||
m_aVoices[i].m_pSample = 0;
|
||||
}
|
||||
lock_release(m_SoundLock);
|
||||
}
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@ public:
|
|||
int Play(int ChannelID, int SampleID, int Flags, float x, float y);
|
||||
virtual int PlayAt(int ChannelID, int SampleID, int Flags, float x, float y);
|
||||
virtual int Play(int ChannelID, int SampleID, int Flags);
|
||||
virtual void Stop(int VoiceID);
|
||||
virtual void Stop(int SampleID);
|
||||
virtual void StopAll();
|
||||
};
|
||||
|
||||
|
|
|
@ -36,7 +36,7 @@ static int aFontSizes[] = {8,9,10,11,12,13,14,15,16,17,18,19,20,36,64};
|
|||
struct CFontChar
|
||||
{
|
||||
int m_ID;
|
||||
|
||||
|
||||
// these values are scaled to the pFont size
|
||||
// width * font_size == real_size
|
||||
float m_Width;
|
||||
|
@ -44,7 +44,7 @@ struct CFontChar
|
|||
float m_OffsetX;
|
||||
float m_OffsetY;
|
||||
float m_AdvanceX;
|
||||
|
||||
|
||||
float m_aUvs[4];
|
||||
int64 m_TouchTime;
|
||||
};
|
||||
|
@ -57,16 +57,16 @@ struct CFontSizeData
|
|||
GLuint m_aTextures[2];
|
||||
int m_TextureWidth;
|
||||
int m_TextureHeight;
|
||||
|
||||
|
||||
int m_NumXChars;
|
||||
int m_NumYChars;
|
||||
|
||||
|
||||
int m_CharMaxWidth;
|
||||
int m_CharMaxHeight;
|
||||
|
||||
|
||||
CFontChar m_aCharacters[MAX_CHARACTERS*MAX_CHARACTERS];
|
||||
|
||||
int m_CurrentCharacter;
|
||||
|
||||
int m_CurrentCharacter;
|
||||
};
|
||||
|
||||
class CFont
|
||||
|
@ -82,7 +82,7 @@ class CTextRender : public IEngineTextRender
|
|||
{
|
||||
IGraphics *m_pGraphics;
|
||||
IGraphics *Graphics() { return m_pGraphics; }
|
||||
|
||||
|
||||
int WordLength(const char *pText)
|
||||
{
|
||||
int s = 1;
|
||||
|
@ -106,13 +106,13 @@ class CTextRender : public IEngineTextRender
|
|||
float m_TextOutlineG;
|
||||
float m_TextOutlineB;
|
||||
float m_TextOutlineA;
|
||||
|
||||
|
||||
int m_FontTextureFormat;
|
||||
|
||||
CFont *m_pDefaultFont;
|
||||
|
||||
FT_Library m_FTLibrary;
|
||||
|
||||
|
||||
int GetFontSizeIndex(int Pixelsize)
|
||||
{
|
||||
for(unsigned i = 0; i < NUM_FONT_SIZES; i++)
|
||||
|
@ -120,18 +120,18 @@ class CTextRender : public IEngineTextRender
|
|||
if(aFontSizes[i] >= Pixelsize)
|
||||
return i;
|
||||
}
|
||||
|
||||
|
||||
return NUM_FONT_SIZES-1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void Grow(unsigned char *pIn, unsigned char *pOut, int w, int h)
|
||||
{
|
||||
for(int y = 0; y < h; y++)
|
||||
for(int x = 0; x < w; x++)
|
||||
{
|
||||
int c = pIn[y*w+x];
|
||||
for(int y = 0; y < h; y++)
|
||||
for(int x = 0; x < w; x++)
|
||||
{
|
||||
int c = pIn[y*w+x];
|
||||
|
||||
for(int sy = -1; sy <= 1; sy++)
|
||||
for(int sx = -1; sx <= 1; sx++)
|
||||
|
@ -142,7 +142,7 @@ class CTextRender : public IEngineTextRender
|
|||
{
|
||||
int Index = GetY*w+GetX;
|
||||
if(pIn[Index] > c)
|
||||
c = pIn[Index];
|
||||
c = pIn[Index];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -157,18 +157,18 @@ class CTextRender : public IEngineTextRender
|
|||
int Height = CharHeight*Ychars;
|
||||
void *pMem = mem_alloc(Width*Height, 1);
|
||||
mem_zero(pMem, Width*Height);
|
||||
|
||||
|
||||
if(pSizeData->m_aTextures[0] == 0)
|
||||
glGenTextures(2, pSizeData->m_aTextures);
|
||||
else
|
||||
FontMemoryUsage -= pSizeData->m_TextureWidth*pSizeData->m_TextureHeight*2;
|
||||
|
||||
|
||||
pSizeData->m_NumXChars = Xchars;
|
||||
pSizeData->m_NumYChars = Ychars;
|
||||
pSizeData->m_TextureWidth = Width;
|
||||
pSizeData->m_TextureHeight = Height;
|
||||
pSizeData->m_CurrentCharacter = 0;
|
||||
|
||||
|
||||
for(int i = 0; i < 2; i++)
|
||||
{
|
||||
glBindTexture(GL_TEXTURE_2D, pSizeData->m_aTextures[i]);
|
||||
|
@ -177,9 +177,9 @@ class CTextRender : public IEngineTextRender
|
|||
glTexImage2D(GL_TEXTURE_2D, 0, m_FontTextureFormat, Width, Height, 0, m_FontTextureFormat, GL_UNSIGNED_BYTE, pMem);
|
||||
FontMemoryUsage += Width*Height;
|
||||
}
|
||||
|
||||
|
||||
dbg_msg("", "pFont memory usage: %d", FontMemoryUsage);
|
||||
|
||||
|
||||
mem_free(pMem);
|
||||
}
|
||||
|
||||
|
@ -198,43 +198,43 @@ class CTextRender : public IEngineTextRender
|
|||
pSizeData->m_NumXChars <<= 1;
|
||||
else
|
||||
pSizeData->m_NumYChars <<= 1;
|
||||
InitTexture(pSizeData, pSizeData->m_CharMaxWidth, pSizeData->m_CharMaxHeight, pSizeData->m_NumXChars, pSizeData->m_NumYChars);
|
||||
InitTexture(pSizeData, pSizeData->m_CharMaxWidth, pSizeData->m_CharMaxHeight, pSizeData->m_NumXChars, pSizeData->m_NumYChars);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// TODO: Refactor: move this into a pFont class
|
||||
void InitIndex(CFont *pFont, int Index)
|
||||
{
|
||||
CFontSizeData *pSizeData = &pFont->m_aSizes[Index];
|
||||
|
||||
|
||||
pSizeData->m_FontSize = aFontSizes[Index];
|
||||
FT_Set_Pixel_Sizes(pFont->m_FtFace, 0, pSizeData->m_FontSize);
|
||||
|
||||
|
||||
int OutlineThickness = AdjustOutlineThicknessToFontSize(1, pSizeData->m_FontSize);
|
||||
|
||||
|
||||
{
|
||||
unsigned GlyphIndex;
|
||||
int MaxH = 0;
|
||||
int MaxW = 0;
|
||||
|
||||
|
||||
int Charcode = FT_Get_First_Char(pFont->m_FtFace, &GlyphIndex);
|
||||
while(GlyphIndex != 0)
|
||||
{
|
||||
{
|
||||
// do stuff
|
||||
FT_Load_Glyph(pFont->m_FtFace, GlyphIndex, FT_LOAD_DEFAULT);
|
||||
|
||||
|
||||
if(pFont->m_FtFace->glyph->metrics.width > MaxW) MaxW = pFont->m_FtFace->glyph->metrics.width; // ignore_convention
|
||||
if(pFont->m_FtFace->glyph->metrics.height > MaxH) MaxH = pFont->m_FtFace->glyph->metrics.height; // ignore_convention
|
||||
Charcode = FT_Get_Next_Char(pFont->m_FtFace, Charcode, &GlyphIndex);
|
||||
}
|
||||
|
||||
|
||||
MaxW = (MaxW>>6)+2+OutlineThickness*2;
|
||||
MaxH = (MaxH>>6)+2+OutlineThickness*2;
|
||||
|
||||
|
||||
for(pSizeData->m_CharMaxWidth = 1; pSizeData->m_CharMaxWidth < MaxW; pSizeData->m_CharMaxWidth <<= 1);
|
||||
for(pSizeData->m_CharMaxHeight = 1; pSizeData->m_CharMaxHeight < MaxH; pSizeData->m_CharMaxHeight <<= 1);
|
||||
}
|
||||
|
||||
|
||||
//dbg_msg("pFont", "init size %d, texture size %d %d", pFont->sizes[index].font_size, w, h);
|
||||
//FT_New_Face(m_FTLibrary, "data/fonts/vera.ttf", 0, &pFont->ft_face);
|
||||
InitTexture(pSizeData, pSizeData->m_CharMaxWidth, pSizeData->m_CharMaxHeight, 8, 8);
|
||||
|
@ -253,7 +253,7 @@ class CTextRender : public IEngineTextRender
|
|||
{
|
||||
int x = (SlotID%pSizeData->m_NumXChars) * (pSizeData->m_TextureWidth/pSizeData->m_NumXChars);
|
||||
int y = (SlotID/pSizeData->m_NumXChars) * (pSizeData->m_TextureHeight/pSizeData->m_NumYChars);
|
||||
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, pSizeData->m_aTextures[Texnum]);
|
||||
glTexSubImage2D(GL_TEXTURE_2D, 0, x, y,
|
||||
pSizeData->m_TextureWidth/pSizeData->m_NumXChars,
|
||||
|
@ -284,13 +284,13 @@ class CTextRender : public IEngineTextRender
|
|||
if(pSizeData->m_aCharacters[i].m_TouchTime < pSizeData->m_aCharacters[Oldest].m_TouchTime)
|
||||
Oldest = i;
|
||||
}
|
||||
|
||||
|
||||
if(time_get()-pSizeData->m_aCharacters[Oldest].m_TouchTime < time_freq())
|
||||
{
|
||||
IncreaseTextureSize(pSizeData);
|
||||
return GetSlot(pSizeData);
|
||||
}
|
||||
|
||||
|
||||
return Oldest;
|
||||
}
|
||||
}
|
||||
|
@ -315,12 +315,12 @@ class CTextRender : public IEngineTextRender
|
|||
}
|
||||
|
||||
pBitmap = &pFont->m_FtFace->glyph->bitmap; // ignore_convention
|
||||
|
||||
|
||||
// fetch slot
|
||||
SlotID = GetSlot(pSizeData);
|
||||
if(SlotID < 0)
|
||||
return -1;
|
||||
|
||||
|
||||
// adjust spacing
|
||||
int OutlineThickness = AdjustOutlineThicknessToFontSize(1, pSizeData->m_FontSize);
|
||||
x += OutlineThickness;
|
||||
|
@ -337,7 +337,7 @@ class CTextRender : public IEngineTextRender
|
|||
}
|
||||
else if(pBitmap->pixel_mode == FT_PIXEL_MODE_MONO) // ignore_convention
|
||||
{
|
||||
for(py = 0; py < pBitmap->rows; py++) // ignore_convention
|
||||
for(py = 0; py < pBitmap->rows; py++) // ignore_convention
|
||||
for(px = 0; px < pBitmap->width; px++) // ignore_convention
|
||||
{
|
||||
if(pBitmap->buffer[py*pBitmap->pitch+px/8]&(1<<(7-(px%8)))) // ignore_convention
|
||||
|
@ -345,13 +345,13 @@ class CTextRender : public IEngineTextRender
|
|||
}
|
||||
}
|
||||
|
||||
if(0) for(py = 0; py < SlotW; py++)
|
||||
for(px = 0; px < SlotH; px++)
|
||||
if(0) for(py = 0; py < SlotW; py++)
|
||||
for(px = 0; px < SlotH; px++)
|
||||
ms_aGlyphData[py*SlotW+px] = 255;
|
||||
|
||||
|
||||
// upload the glyph
|
||||
UploadGlyph(pSizeData, 0, SlotID, Chr, ms_aGlyphData);
|
||||
|
||||
|
||||
if(OutlineThickness == 1)
|
||||
{
|
||||
Grow(ms_aGlyphData, ms_aGlyphDataOutlined, SlotW, SlotH);
|
||||
|
@ -366,7 +366,7 @@ class CTextRender : public IEngineTextRender
|
|||
}
|
||||
UploadGlyph(pSizeData, 1, SlotID, Chr, ms_aGlyphData);
|
||||
}
|
||||
|
||||
|
||||
// set char info
|
||||
{
|
||||
CFontChar *pFontchr = &pSizeData->m_aCharacters[SlotID];
|
||||
|
@ -375,27 +375,27 @@ class CTextRender : public IEngineTextRender
|
|||
float Vscale = 1.0f/pSizeData->m_TextureHeight;
|
||||
int Height = pBitmap->rows + OutlineThickness*2 + 2; // ignore_convention
|
||||
int Width = pBitmap->width + OutlineThickness*2 + 2; // ignore_convention
|
||||
|
||||
|
||||
pFontchr->m_ID = Chr;
|
||||
pFontchr->m_Height = Height * Scale;
|
||||
pFontchr->m_Width = Width * Scale;
|
||||
pFontchr->m_OffsetX = (pFont->m_FtFace->glyph->bitmap_left-1) * Scale; // ignore_convention
|
||||
pFontchr->m_OffsetY = (pSizeData->m_FontSize - pFont->m_FtFace->glyph->bitmap_top) * Scale; // ignore_convention
|
||||
pFontchr->m_AdvanceX = (pFont->m_FtFace->glyph->advance.x>>6) * Scale; // ignore_convention
|
||||
|
||||
|
||||
pFontchr->m_aUvs[0] = (SlotID%pSizeData->m_NumXChars) / (float)(pSizeData->m_NumXChars);
|
||||
pFontchr->m_aUvs[1] = (SlotID/pSizeData->m_NumXChars) / (float)(pSizeData->m_NumYChars);
|
||||
pFontchr->m_aUvs[2] = pFontchr->m_aUvs[0] + Width*Uscale;
|
||||
pFontchr->m_aUvs[3] = pFontchr->m_aUvs[1] + Height*Vscale;
|
||||
}
|
||||
|
||||
|
||||
return SlotID;
|
||||
}
|
||||
|
||||
CFontChar *GetChar(CFont *pFont, CFontSizeData *pSizeData, int Chr)
|
||||
{
|
||||
CFontChar *pFontchr = NULL;
|
||||
|
||||
|
||||
// search for the character
|
||||
// TODO: remove this linear search
|
||||
int i;
|
||||
|
@ -407,7 +407,7 @@ class CTextRender : public IEngineTextRender
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// check if we need to render the character
|
||||
if(!pFontchr)
|
||||
{
|
||||
|
@ -415,12 +415,12 @@ class CTextRender : public IEngineTextRender
|
|||
if(Index >= 0)
|
||||
pFontchr = &pSizeData->m_aCharacters[Index];
|
||||
}
|
||||
|
||||
|
||||
// touch the character
|
||||
// TODO: don't call time_get here
|
||||
if(pFontchr)
|
||||
pFontchr->m_TouchTime = time_get();
|
||||
|
||||
|
||||
return pFontchr;
|
||||
}
|
||||
|
||||
|
@ -436,8 +436,8 @@ class CTextRender : public IEngineTextRender
|
|||
FT_Get_Kerning(pFont->m_FtFace, Left, Right, FT_KERNING_DEFAULT, &Kerning);
|
||||
return (Kerning.x>>6);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public:
|
||||
CTextRender()
|
||||
{
|
||||
|
@ -457,21 +457,21 @@ public:
|
|||
// GL_LUMINANCE can be good for debugging
|
||||
m_FontTextureFormat = GL_ALPHA;
|
||||
}
|
||||
|
||||
|
||||
virtual void Init()
|
||||
{
|
||||
m_pGraphics = Kernel()->RequestInterface<IGraphics>();
|
||||
FT_Init_FreeType(&m_FTLibrary);
|
||||
}
|
||||
|
||||
|
||||
|
||||
virtual CFont *LoadFont(const char *pFilename)
|
||||
{
|
||||
CFont *pFont = (CFont *)mem_alloc(sizeof(CFont), 1);
|
||||
|
||||
|
||||
mem_zero(pFont, sizeof(*pFont));
|
||||
str_copy(pFont->m_aFilename, pFilename, sizeof(pFont->m_aFilename));
|
||||
|
||||
|
||||
if(FT_New_Face(m_FTLibrary, pFont->m_aFilename, 0, &pFont->m_FtFace))
|
||||
{
|
||||
mem_free(pFont);
|
||||
|
@ -480,7 +480,7 @@ public:
|
|||
|
||||
for(unsigned i = 0; i < NUM_FONT_SIZES; i++)
|
||||
pFont->m_aSizes[i].m_FontSize = -1;
|
||||
|
||||
|
||||
dbg_msg("textrender", "loaded pFont from '%s'", pFilename);
|
||||
return pFont;
|
||||
};
|
||||
|
@ -495,8 +495,8 @@ public:
|
|||
dbg_msg("textrender", "default pFont set %p", pFont);
|
||||
m_pDefaultFont = pFont;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
virtual void SetCursor(CTextCursor *pCursor, float x, float y, float FontSize, int Flags)
|
||||
{
|
||||
mem_zero(pCursor, sizeof(*pCursor));
|
||||
|
@ -510,8 +510,8 @@ public:
|
|||
pCursor->m_Flags = Flags;
|
||||
pCursor->m_CharCount = 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
virtual void Text(void *pFontSetV, float x, float y, float Size, const char *pText, int MaxWidth)
|
||||
{
|
||||
CTextCursor Cursor;
|
||||
|
@ -527,7 +527,7 @@ public:
|
|||
TextEx(&Cursor, pText, Length);
|
||||
return Cursor.m_X;
|
||||
}
|
||||
|
||||
|
||||
virtual int TextLineCount(void *pFontSetV, float Size, const char *pText, float LineWidth)
|
||||
{
|
||||
CTextCursor Cursor;
|
||||
|
@ -552,12 +552,12 @@ public:
|
|||
m_TextOutlineB = b;
|
||||
m_TextOutlineA = a;
|
||||
}
|
||||
|
||||
|
||||
virtual void TextEx(CTextCursor *pCursor, const char *pText, int Length)
|
||||
{
|
||||
CFont *pFont = pCursor->m_pFont;
|
||||
CFontSizeData *pSizeData = NULL;
|
||||
|
||||
|
||||
//dbg_msg("textrender", "rendering text '%s'", text);
|
||||
|
||||
float ScreenX0, ScreenY0, ScreenX1, ScreenY1;
|
||||
|
@ -576,7 +576,7 @@ public:
|
|||
|
||||
// to correct coords, convert to screen coords, round, and convert back
|
||||
Graphics()->GetScreen(&ScreenX0, &ScreenY0, &ScreenX1, &ScreenY1);
|
||||
|
||||
|
||||
FakeToScreenX = (Graphics()->ScreenWidth()/(ScreenX1-ScreenX0));
|
||||
FakeToScreenY = (Graphics()->ScreenHeight()/(ScreenY1-ScreenY0));
|
||||
ActualX = (int)(pCursor->m_X * FakeToScreenX);
|
||||
|
@ -592,7 +592,7 @@ public:
|
|||
// fetch pFont data
|
||||
if(!pFont)
|
||||
pFont = m_pDefaultFont;
|
||||
|
||||
|
||||
if(!pFont)
|
||||
return;
|
||||
|
||||
|
@ -600,11 +600,11 @@ public:
|
|||
RenderSetup(pFont, ActualSize);
|
||||
|
||||
float Scale = 1/pSizeData->m_FontSize;
|
||||
|
||||
|
||||
// set length
|
||||
if(Length < 0)
|
||||
Length = str_length(pText);
|
||||
|
||||
|
||||
pEnd = pText + Length;
|
||||
|
||||
// if we don't want to render, we can just skip the first outline pass
|
||||
|
@ -649,7 +649,7 @@ public:
|
|||
Compare.m_Flags &= ~TEXTFLAG_RENDER;
|
||||
Compare.m_LineWidth = -1;
|
||||
TextEx(&Compare, pText, Wlen);
|
||||
|
||||
|
||||
if(Compare.m_X-DrawX > pCursor->m_LineWidth)
|
||||
{
|
||||
// word can't be fitted in one line, cut it
|
||||
|
@ -659,11 +659,11 @@ public:
|
|||
Cutter.m_Y = DrawY;
|
||||
Cutter.m_Flags &= ~TEXTFLAG_RENDER;
|
||||
Cutter.m_Flags |= TEXTFLAG_STOP_AT_END;
|
||||
|
||||
|
||||
TextEx(&Cutter, (const char *)pCurrent, Wlen);
|
||||
Wlen = Cutter.m_CharCount;
|
||||
NewLine = 1;
|
||||
|
||||
|
||||
if(Wlen <= 3) // if we can't place 3 chars of the word on this line, take the next
|
||||
Wlen = 0;
|
||||
}
|
||||
|
@ -672,10 +672,10 @@ public:
|
|||
NewLine = 1;
|
||||
Wlen = 0;
|
||||
}
|
||||
|
||||
|
||||
pBatchEnd = pCurrent + Wlen;
|
||||
}
|
||||
|
||||
|
||||
const char *pTmp = pCurrent;
|
||||
int NextCharacter = str_utf8_decode(&pTmp);
|
||||
while(pCurrent < pBatchEnd)
|
||||
|
@ -683,7 +683,7 @@ public:
|
|||
int Character = NextCharacter;
|
||||
pCurrent = pTmp;
|
||||
NextCharacter = str_utf8_decode(&pTmp);
|
||||
|
||||
|
||||
if(Character == '\n')
|
||||
{
|
||||
DrawX = pCursor->m_StartX;
|
||||
|
@ -718,14 +718,14 @@ public:
|
|||
pCursor->m_CharCount++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(NewLine)
|
||||
{
|
||||
DrawX = pCursor->m_StartX;
|
||||
DrawY += Size;
|
||||
GotNewLine = 1;
|
||||
DrawX = (int)(DrawX * FakeToScreenX) / FakeToScreenX; // realign
|
||||
DrawY = (int)(DrawY * FakeToScreenY) / FakeToScreenY;
|
||||
DrawY = (int)(DrawY * FakeToScreenY) / FakeToScreenY;
|
||||
++LineCount;
|
||||
}
|
||||
}
|
||||
|
@ -736,11 +736,11 @@ public:
|
|||
|
||||
pCursor->m_X = DrawX;
|
||||
pCursor->m_LineCount = LineCount;
|
||||
|
||||
|
||||
if(GotNewLine)
|
||||
pCursor->m_Y = DrawY;
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
IEngineTextRender *CreateEngineTextRender() { return new CTextRender; }
|
||||
|
|
|
@ -15,9 +15,9 @@ public:
|
|||
virtual void Reset() = 0;
|
||||
virtual void RestoreStrings() = 0;
|
||||
virtual void Save() = 0;
|
||||
|
||||
|
||||
virtual void RegisterCallback(SAVECALLBACKFUNC pfnFunc, void *pUserData) = 0;
|
||||
|
||||
|
||||
virtual void WriteLine(const char *pLine) = 0;
|
||||
};
|
||||
|
||||
|
|
|
@ -25,11 +25,11 @@ public:
|
|||
public:
|
||||
IResult() { m_NumArgs = 0; }
|
||||
virtual ~IResult() {}
|
||||
|
||||
|
||||
virtual int GetInteger(unsigned Index) = 0;
|
||||
virtual float GetFloat(unsigned Index) = 0;
|
||||
virtual const char *GetString(unsigned Index) = 0;
|
||||
|
||||
|
||||
int NumArguments() const { return m_NumArgs; }
|
||||
|
||||
// DDRace
|
||||
|
@ -37,7 +37,7 @@ public:
|
|||
virtual void Print(int Level, const char *pFrom, const char *pStr) = 0;
|
||||
virtual int GetVictim() = 0;
|
||||
};
|
||||
|
||||
|
||||
class CCommandInfo
|
||||
{
|
||||
public:
|
||||
|
@ -59,16 +59,16 @@ public:
|
|||
virtual void PossibleCommands(const char *pStr, int FlagMask, FPossibleCallback pfnCallback, void *pUser) = 0;
|
||||
virtual void ParseArguments(int NumArgs, const char **ppArguments) = 0;
|
||||
|
||||
virtual void Register(const char *pName, const char *pParams,
|
||||
virtual void Register(const char *pName, const char *pParams,
|
||||
int Flags, FCommandCallback pfnFunc, void *pUser, const char *pHelp, const int Level) = 0;
|
||||
virtual void Chain(const char *pName, FChainCommandCallback pfnChainFunc, void *pUser) = 0;
|
||||
virtual void StoreCommands(bool Store, int ClientID) = 0;
|
||||
|
||||
|
||||
virtual bool LineIsValid(const char *pStr) = 0;
|
||||
//virtual void ExecuteLine(const char *Sptr) = 0;
|
||||
//virtual void ExecuteLineStroked(int Stroke, const char *pStr) = 0;
|
||||
//virtual void ExecuteFile(const char *pFilename) = 0;
|
||||
|
||||
|
||||
virtual void RegisterPrintCallback(FPrintCallback pfnPrintCallback, void *pUserData) = 0;
|
||||
virtual void Print(int Level, const char *pFrom, const char *pStr) = 0;
|
||||
|
||||
|
|
|
@ -21,11 +21,11 @@ public:
|
|||
{
|
||||
MAX_FRIENDS=128,
|
||||
};
|
||||
|
||||
|
||||
virtual void Init() = 0;
|
||||
|
||||
|
||||
virtual int NumFriends() const = 0;
|
||||
virtual const CFriendInfo *GetFriend(int Index) const = 0;
|
||||
virtual const CFriendInfo *GetFriend(int Index) const = 0;
|
||||
virtual bool IsFriend(const char *pName, const char *pClan, bool PlayersOnly) const = 0;
|
||||
|
||||
virtual void AddFriend(const char *pName, const char *pClan) = 0;
|
||||
|
|
|
@ -19,11 +19,11 @@ public:
|
|||
/* Variable: width
|
||||
Contains the width of the image */
|
||||
int m_Width;
|
||||
|
||||
|
||||
/* Variable: height
|
||||
Contains the height of the image */
|
||||
int m_Height;
|
||||
|
||||
|
||||
/* Variable: format
|
||||
Contains the format of the image. See <Image Formats> for more information. */
|
||||
int m_Format;
|
||||
|
@ -61,27 +61,27 @@ public:
|
|||
int ScreenWidth() const { return m_ScreenWidth; }
|
||||
int ScreenHeight() const { return m_ScreenHeight; }
|
||||
float ScreenAspect() const { return (float)ScreenWidth()/(float)ScreenHeight(); }
|
||||
|
||||
|
||||
virtual void Clear(float r, float g, float b) = 0;
|
||||
|
||||
|
||||
virtual void ClipEnable(int x, int y, int w, int h) = 0;
|
||||
virtual void ClipDisable() = 0;
|
||||
|
||||
|
||||
virtual void MapScreen(float TopLeftX, float TopLeftY, float BottomRightX, float BottomRightY) = 0;
|
||||
virtual void GetScreen(float *pTopLeftX, float *pTopLeftY, float *pBottomRightX, float *pBottomRightY) = 0;
|
||||
|
||||
|
||||
// TODO: These should perhaps not be virtuals
|
||||
virtual void BlendNone() = 0;
|
||||
virtual void BlendNormal() = 0;
|
||||
virtual void BlendAdditive() = 0;
|
||||
virtual int MemoryUsage() const = 0;
|
||||
|
||||
|
||||
virtual int LoadPNG(CImageInfo *pImg, const char *pFilename, int StorageType) =0;
|
||||
virtual int UnloadTexture(int Index) = 0;
|
||||
virtual int LoadTextureRaw(int Width, int Height, int Format, const void *pData, int StoreFormat, int Flags) = 0;
|
||||
virtual int LoadTexture(const char *pFilename, int StorageType, int StoreFormat, int Flags) = 0;
|
||||
virtual void TextureSet(int TextureID) = 0;
|
||||
|
||||
|
||||
struct CLineItem
|
||||
{
|
||||
float m_X0, m_Y0, m_X1, m_Y1;
|
||||
|
@ -91,13 +91,13 @@ public:
|
|||
virtual void LinesBegin() = 0;
|
||||
virtual void LinesEnd() = 0;
|
||||
virtual void LinesDraw(const CLineItem *pArray, int Num) = 0;
|
||||
|
||||
|
||||
virtual void QuadsBegin() = 0;
|
||||
virtual void QuadsEnd() = 0;
|
||||
virtual void QuadsSetRotation(float Angle) = 0;
|
||||
virtual void QuadsSetSubset(float TopLeftY, float TopLeftV, float BottomRightU, float BottomRightV) = 0;
|
||||
virtual void QuadsSetSubsetFree(float x0, float y0, float x1, float y1, float x2, float y2, float x3, float y3) = 0;
|
||||
|
||||
|
||||
struct CQuadItem
|
||||
{
|
||||
float m_X, m_Y, m_Width, m_Height;
|
||||
|
@ -106,7 +106,7 @@ public:
|
|||
};
|
||||
virtual void QuadsDraw(CQuadItem *pArray, int Num) = 0;
|
||||
virtual void QuadsDrawTL(const CQuadItem *pArray, int Num) = 0;
|
||||
|
||||
|
||||
struct CFreeformItem
|
||||
{
|
||||
float m_X0, m_Y0, m_X1, m_Y1, m_X2, m_Y2, m_X3, m_Y3;
|
||||
|
@ -116,7 +116,7 @@ public:
|
|||
};
|
||||
virtual void QuadsDrawFreeform(const CFreeformItem *pArray, int Num) = 0;
|
||||
virtual void QuadsText(float x, float y, float Size, float r, float g, float b, float a, const char *pText) = 0;
|
||||
|
||||
|
||||
struct CColorVertex
|
||||
{
|
||||
int m_Index;
|
||||
|
@ -126,7 +126,7 @@ public:
|
|||
};
|
||||
virtual void SetColorVertex(const CColorVertex *pArray, int Num) = 0;
|
||||
virtual void SetColor(float r, float g, float b, float a) = 0;
|
||||
|
||||
|
||||
virtual void TakeScreenshot(const char *pFilename) = 0;
|
||||
virtual int GetVideoModes(CVideoMode *pModes, int MaxModes) = 0;
|
||||
|
||||
|
@ -139,13 +139,13 @@ class IEngineGraphics : public IGraphics
|
|||
public:
|
||||
virtual bool Init() = 0;
|
||||
virtual void Shutdown() = 0;
|
||||
|
||||
|
||||
virtual void Minimize() = 0;
|
||||
virtual void Maximize() = 0;
|
||||
|
||||
|
||||
virtual int WindowActive() = 0;
|
||||
virtual int WindowOpen() = 0;
|
||||
|
||||
|
||||
};
|
||||
|
||||
extern IEngineGraphics *CreateEngineGraphics();
|
||||
|
|
|
@ -41,7 +41,7 @@ protected:
|
|||
|
||||
int KeyWasPressed(int Key) { return m_aInputState[m_InputCurrent^1][Key]; }
|
||||
|
||||
public:
|
||||
public:
|
||||
enum
|
||||
{
|
||||
FLAG_PRESS=1,
|
||||
|
@ -53,7 +53,7 @@ public:
|
|||
int NumEvents() const { return m_NumEvents; }
|
||||
void ClearEvents() { m_NumEvents = 0; }
|
||||
CEvent GetEvent(int Index) const
|
||||
{
|
||||
{
|
||||
if(Index < 0 || Index >= m_NumEvents)
|
||||
{
|
||||
IInput::CEvent e = {0,0};
|
||||
|
@ -61,19 +61,19 @@ public:
|
|||
}
|
||||
return m_aInputEvents[Index];
|
||||
}
|
||||
|
||||
|
||||
// keys
|
||||
int KeyPressed(int Key) { return m_aInputState[m_InputCurrent][Key]; }
|
||||
int KeyReleases(int Key) { return m_aInputCount[m_InputCurrent][Key].m_Releases; }
|
||||
int KeyPresses(int Key) { return m_aInputCount[m_InputCurrent][Key].m_Presses; }
|
||||
int KeyDown(int Key) { return KeyPressed(Key)&&!KeyWasPressed(Key); }
|
||||
const char *KeyName(int Key) { return (Key >= 0 && Key < 512) ? g_aaKeyStrings[Key] : g_aaKeyStrings[0]; }
|
||||
|
||||
|
||||
//
|
||||
virtual void MouseModeRelative() = 0;
|
||||
virtual void MouseModeAbsolute() = 0;
|
||||
virtual int MouseDoubleClick() = 0;
|
||||
|
||||
|
||||
virtual void MouseRelative(float *x, float *y) = 0;
|
||||
};
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@ protected:
|
|||
public:
|
||||
IInterface() : m_pKernel(0) {}
|
||||
virtual ~IInterface() {}
|
||||
|
||||
|
||||
//virtual unsigned InterfaceID() = 0;
|
||||
//virtual const char *InterfaceName() = 0;
|
||||
};
|
||||
|
@ -27,7 +27,7 @@ public:
|
|||
public: \
|
||||
static const char *InterfaceName() { return Name; } \
|
||||
private:
|
||||
|
||||
|
||||
//virtual unsigned InterfaceID() { return INTERFACE_ID; }
|
||||
//virtual const char *InterfaceName() { return name; }
|
||||
|
||||
|
@ -55,7 +55,7 @@ public:
|
|||
{
|
||||
return ReregisterInterfaceImpl(TINTERFACE::InterfaceName(), pInterface);
|
||||
}
|
||||
|
||||
|
||||
// Usage example:
|
||||
// IMyInterface *pMyHandle = Kernel()->RequestInterface<IMyInterface>()
|
||||
template<class TINTERFACE>
|
||||
|
|
|
@ -21,7 +21,7 @@ public:
|
|||
const char *m_pName;
|
||||
int m_Latency;
|
||||
};
|
||||
|
||||
|
||||
int Tick() const { return m_CurrentGameTick; }
|
||||
int TickSpeed() const { return m_TickSpeed; }
|
||||
|
||||
|
@ -32,7 +32,7 @@ public:
|
|||
virtual int GetClientInfo(int ClientID, CClientInfo *pInfo) = 0;
|
||||
virtual void GetClientAddr(int ClientID, char *pAddrStr, int Size) = 0;
|
||||
virtual int *LatestInput(int ClientID, int *pSize) = 0;
|
||||
|
||||
|
||||
virtual int SendMsg(CMsgPacker *pMsg, int Flags, int ClientID) = 0;
|
||||
|
||||
template<class T>
|
||||
|
@ -43,18 +43,18 @@ public:
|
|||
return -1;
|
||||
return SendMsg(&Packer, Flags, ClientID);
|
||||
}
|
||||
|
||||
|
||||
virtual void SetClientName(int ClientID, char const *pName) = 0;
|
||||
virtual void SetClientClan(int ClientID, char const *pClan) = 0;
|
||||
virtual void SetClientCountry(int ClientID, int Country) = 0;
|
||||
virtual void SetClientScore(int ClientID, int Score) = 0;
|
||||
|
||||
|
||||
virtual int SnapNewID() = 0;
|
||||
virtual void SnapFreeID(int ID) = 0;
|
||||
virtual void *SnapNewItem(int Type, int ID, int Size) = 0;
|
||||
|
||||
virtual void SnapSetStaticsize(int ItemType, int Size) = 0;
|
||||
|
||||
|
||||
virtual int IsAuthed(int ClientID) = 0;
|
||||
virtual void Kick(int ClientID, const char *pReason) = 0;
|
||||
|
||||
|
@ -73,12 +73,12 @@ public:
|
|||
virtual void OnInit() = 0;
|
||||
virtual void OnConsoleInit() = 0;
|
||||
virtual void OnShutdown() = 0;
|
||||
|
||||
|
||||
virtual void OnTick() = 0;
|
||||
virtual void OnPreSnap() = 0;
|
||||
virtual void OnSnap(int ClientID) = 0;
|
||||
virtual void OnPostSnap() = 0;
|
||||
|
||||
|
||||
virtual void OnMessage(int MsgID, CUnpacker *pUnpacker, int ClientID) = 0;
|
||||
|
||||
virtual void OnClientConnected(int ClientID) = 0;
|
||||
|
@ -89,7 +89,7 @@ public:
|
|||
|
||||
virtual bool IsClientReady(int ClientID) = 0;
|
||||
virtual bool IsClientPlayer(int ClientID) = 0;
|
||||
|
||||
|
||||
virtual const char *GameType() = 0;
|
||||
virtual const char *Version() = 0;
|
||||
virtual const char *NetVersion() = 0;
|
||||
|
|
|
@ -41,15 +41,15 @@ void CRegister::RegisterSendFwcheckresponse(NETADDR *pAddr)
|
|||
Packet.m_pData = SERVERBROWSE_FWRESPONSE;
|
||||
m_pNetServer->Send(&Packet);
|
||||
}
|
||||
|
||||
|
||||
void CRegister::RegisterSendHeartbeat(NETADDR Addr)
|
||||
{
|
||||
static unsigned char aData[sizeof(SERVERBROWSE_HEARTBEAT) + 2];
|
||||
unsigned short Port = g_Config.m_SvPort;
|
||||
CNetChunk Packet;
|
||||
|
||||
|
||||
mem_copy(aData, SERVERBROWSE_HEARTBEAT, sizeof(SERVERBROWSE_HEARTBEAT));
|
||||
|
||||
|
||||
Packet.m_ClientID = -1;
|
||||
Packet.m_Address = Addr;
|
||||
Packet.m_Flags = NETSENDFLAG_CONNLESS;
|
||||
|
@ -118,7 +118,7 @@ void CRegister::RegisterUpdate(int Nettype)
|
|||
else if(m_RegisterState == REGISTERSTATE_UPDATE_ADDRS)
|
||||
{
|
||||
m_RegisterRegisteredServer = -1;
|
||||
|
||||
|
||||
if(!m_pMasterServer->IsRefreshing())
|
||||
{
|
||||
int i;
|
||||
|
@ -137,7 +137,7 @@ void CRegister::RegisterUpdate(int Nettype)
|
|||
m_aMasterserverInfo[i].m_Count = -1;
|
||||
m_aMasterserverInfo[i].m_LastSend = 0;
|
||||
}
|
||||
|
||||
|
||||
m_pConsole->Print(IConsole::OUTPUT_LEVEL_STANDARD, "register", "fetching server counts");
|
||||
RegisterNewState(REGISTERSTATE_QUERY_COUNT);
|
||||
}
|
||||
|
@ -149,7 +149,7 @@ void CRegister::RegisterUpdate(int Nettype)
|
|||
{
|
||||
if(!m_aMasterserverInfo[i].m_Valid)
|
||||
continue;
|
||||
|
||||
|
||||
if(m_aMasterserverInfo[i].m_Count == -1)
|
||||
{
|
||||
Left++;
|
||||
|
@ -160,7 +160,7 @@ void CRegister::RegisterUpdate(int Nettype)
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// check if we are done or timed out
|
||||
if(Left == 0 || Now > m_RegisterStateStart+Freq*3)
|
||||
{
|
||||
|
@ -171,7 +171,7 @@ void CRegister::RegisterUpdate(int Nettype)
|
|||
{
|
||||
if(!m_aMasterserverInfo[i].m_Valid || m_aMasterserverInfo[i].m_Count == -1)
|
||||
continue;
|
||||
|
||||
|
||||
if(Best == -1 || m_aMasterserverInfo[i].m_Count < m_aMasterserverInfo[Best].m_Count)
|
||||
Best = i;
|
||||
}
|
||||
|
@ -184,7 +184,7 @@ void CRegister::RegisterUpdate(int Nettype)
|
|||
RegisterNewState(REGISTERSTATE_ERROR);
|
||||
}
|
||||
else
|
||||
{
|
||||
{
|
||||
char aBuf[256];
|
||||
str_format(aBuf, sizeof(aBuf), "chose '%s' as master, sending heartbeats", m_pMasterServer->GetName(m_RegisterRegisteredServer));
|
||||
m_pConsole->Print(IConsole::OUTPUT_LEVEL_STANDARD, "register", aBuf);
|
||||
|
@ -201,7 +201,7 @@ void CRegister::RegisterUpdate(int Nettype)
|
|||
m_aMasterserverInfo[m_RegisterRegisteredServer].m_LastSend = Now;
|
||||
RegisterSendHeartbeat(m_aMasterserverInfo[m_RegisterRegisteredServer].m_Addr);
|
||||
}
|
||||
|
||||
|
||||
if(Now > m_RegisterStateStart+Freq*60)
|
||||
{
|
||||
m_pConsole->Print(IConsole::OUTPUT_LEVEL_STANDARD, "register", "WARNING: Master server is not responding, switching master");
|
||||
|
@ -212,9 +212,9 @@ void CRegister::RegisterUpdate(int Nettype)
|
|||
{
|
||||
if(m_RegisterFirst)
|
||||
m_pConsole->Print(IConsole::OUTPUT_LEVEL_STANDARD, "register", "server registered");
|
||||
|
||||
|
||||
m_RegisterFirst = 0;
|
||||
|
||||
|
||||
// check if we should send new heartbeat again
|
||||
if(Now > m_RegisterStateStart+Freq)
|
||||
{
|
||||
|
@ -253,7 +253,7 @@ int CRegister::RegisterProcessPacket(CNetChunk *pPacket)
|
|||
}
|
||||
if(!Valid)
|
||||
return 0;
|
||||
|
||||
|
||||
if(pPacket->m_DataSize == sizeof(SERVERBROWSE_FWCHECK) &&
|
||||
mem_comp(pPacket->m_pData, SERVERBROWSE_FWCHECK, sizeof(SERVERBROWSE_FWCHECK)) == 0)
|
||||
{
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
#include "register.h"
|
||||
#include "server.h"
|
||||
|
||||
#if defined(CONF_FAMILY_WINDOWS)
|
||||
#if defined(CONF_FAMILY_WINDOWS)
|
||||
#define _WIN32_WINNT 0x0501
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
|
@ -82,7 +82,7 @@ void CSnapIDPool::Reset()
|
|||
m_aIDs[i].m_Next = i+1;
|
||||
m_aIDs[i].m_State = 0;
|
||||
}
|
||||
|
||||
|
||||
m_aIDs[MAX_IDS-1].m_Next = -1;
|
||||
m_FirstFree = 0;
|
||||
m_FirstTimed = -1;
|
||||
|
@ -95,17 +95,17 @@ void CSnapIDPool::Reset()
|
|||
void CSnapIDPool::RemoveFirstTimeout()
|
||||
{
|
||||
int NextTimed = m_aIDs[m_FirstTimed].m_Next;
|
||||
|
||||
|
||||
// add it to the free list
|
||||
m_aIDs[m_FirstTimed].m_Next = m_FirstFree;
|
||||
m_aIDs[m_FirstTimed].m_State = 0;
|
||||
m_FirstFree = m_FirstTimed;
|
||||
|
||||
|
||||
// remove it from the timed list
|
||||
m_FirstTimed = NextTimed;
|
||||
if(m_FirstTimed == -1)
|
||||
m_LastTimed = -1;
|
||||
|
||||
|
||||
m_Usage--;
|
||||
}
|
||||
|
||||
|
@ -116,7 +116,7 @@ int CSnapIDPool::NewID()
|
|||
// process timed ids
|
||||
while(m_FirstTimed != -1 && m_aIDs[m_FirstTimed].m_Timeout < Now)
|
||||
RemoveFirstTimeout();
|
||||
|
||||
|
||||
int ID = m_FirstFree;
|
||||
dbg_assert(ID != -1, "id error");
|
||||
if(ID == -1)
|
||||
|
@ -145,7 +145,7 @@ void CSnapIDPool::FreeID(int ID)
|
|||
m_aIDs[ID].m_State = 2;
|
||||
m_aIDs[ID].m_Timeout = time_get()+time_freq()*5;
|
||||
m_aIDs[ID].m_Next = -1;
|
||||
|
||||
|
||||
if(m_LastTimed != -1)
|
||||
{
|
||||
m_aIDs[m_LastTimed].m_Next = ID;
|
||||
|
@ -157,7 +157,7 @@ void CSnapIDPool::FreeID(int ID)
|
|||
m_LastTimed = ID;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void CServer::CClient::Reset()
|
||||
{
|
||||
// reset input
|
||||
|
@ -176,15 +176,15 @@ void CServer::CClient::Reset()
|
|||
CServer::CServer() : m_DemoRecorder(&m_SnapshotDelta)
|
||||
{
|
||||
m_TickSpeed = SERVER_TICK_SPEED;
|
||||
|
||||
|
||||
m_pGameServer = 0;
|
||||
|
||||
|
||||
m_CurrentGameTick = 0;
|
||||
m_RunServer = 1;
|
||||
|
||||
m_pCurrentMapData = 0;
|
||||
m_CurrentMapSize = 0;
|
||||
|
||||
|
||||
m_MapReload = 0;
|
||||
|
||||
m_RconClientID = -1;
|
||||
|
@ -209,12 +209,12 @@ int CServer::TrySetClientName(int ClientID, const char *pName)
|
|||
str_format(aBuf, sizeof(aBuf), "'%s' -> '%s'", pName, aTrimmedName);
|
||||
Console()->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "server", aBuf);
|
||||
pName = aTrimmedName;
|
||||
|
||||
|
||||
|
||||
|
||||
// check for empty names
|
||||
if(!pName[0])
|
||||
return -1;
|
||||
|
||||
|
||||
// make sure that two clients doesn't have the same name
|
||||
for(int i = 0; i < MAX_CLIENTS; i++)
|
||||
if(i != ClientID && m_aClients[i].m_State >= CClient::STATE_READY)
|
||||
|
@ -234,10 +234,10 @@ void CServer::SetClientName(int ClientID, const char *pName)
|
|||
{
|
||||
if(ClientID < 0 || ClientID >= MAX_CLIENTS || m_aClients[ClientID].m_State < CClient::STATE_READY)
|
||||
return;
|
||||
|
||||
|
||||
if(!pName)
|
||||
return;
|
||||
|
||||
|
||||
char aNameTry[MAX_NAME_LENGTH];
|
||||
str_copy(aNameTry, pName, MAX_NAME_LENGTH);
|
||||
if(TrySetClientName(ClientID, aNameTry))
|
||||
|
@ -256,7 +256,7 @@ void CServer::SetClientClan(int ClientID, const char *pClan)
|
|||
{
|
||||
if(ClientID < 0 || ClientID >= MAX_CLIENTS || m_aClients[ClientID].m_State < CClient::STATE_READY || !pClan)
|
||||
return;
|
||||
|
||||
|
||||
str_copy(m_aClients[ClientID].m_aClan, pClan, MAX_CLAN_LENGTH);
|
||||
}
|
||||
|
||||
|
@ -264,7 +264,7 @@ void CServer::SetClientCountry(int ClientID, int Country)
|
|||
{
|
||||
if(ClientID < 0 || ClientID >= MAX_CLIENTS || m_aClients[ClientID].m_State < CClient::STATE_READY)
|
||||
return;
|
||||
|
||||
|
||||
m_aClients[ClientID].m_Country = Country;
|
||||
}
|
||||
|
||||
|
@ -287,7 +287,7 @@ void CServer::Kick(int ClientID, const char *pReason)
|
|||
Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "server", "you can't kick yourself");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
m_NetServer.Drop(ClientID, pReason);
|
||||
}
|
||||
|
||||
|
@ -353,7 +353,7 @@ void CServer::GetClientAddr(int ClientID, char *pAddrStr, int Size)
|
|||
net_addr_str(&Addr, pAddrStr, Size);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
int *CServer::LatestInput(int ClientID, int *size)
|
||||
{
|
||||
|
@ -370,7 +370,7 @@ const char *CServer::ClientName(int ClientID)
|
|||
return m_aClients[ClientID].m_aName;
|
||||
else
|
||||
return "(connecting client)";
|
||||
|
||||
|
||||
}
|
||||
|
||||
const char *CServer::ClientClan(int ClientID)
|
||||
|
@ -408,13 +408,13 @@ int CServer::SendMsgEx(CMsgPacker *pMsg, int Flags, int ClientID, bool System)
|
|||
CNetChunk Packet;
|
||||
if(!pMsg)
|
||||
return -1;
|
||||
|
||||
|
||||
mem_zero(&Packet, sizeof(CNetChunk));
|
||||
|
||||
|
||||
Packet.m_ClientID = ClientID;
|
||||
Packet.m_pData = pMsg->Data();
|
||||
Packet.m_DataSize = pMsg->Size();
|
||||
|
||||
|
||||
// HACK: modify the message id in the packet and store the system flag
|
||||
*((unsigned char*)Packet.m_pData) <<= 1;
|
||||
if(System)
|
||||
|
@ -424,7 +424,7 @@ int CServer::SendMsgEx(CMsgPacker *pMsg, int Flags, int ClientID, bool System)
|
|||
Packet.m_Flags |= NETSENDFLAG_VITAL;
|
||||
if(Flags&MSGFLAG_FLUSH)
|
||||
Packet.m_Flags |= NETSENDFLAG_FLUSH;
|
||||
|
||||
|
||||
// write message to demo recorder
|
||||
if(!(Flags&MSGFLAG_NORECORD))
|
||||
m_DemoRecorder.RecordMessage(pMsg->Data(), pMsg->Size());
|
||||
|
@ -451,7 +451,7 @@ int CServer::SendMsgEx(CMsgPacker *pMsg, int Flags, int ClientID, bool System)
|
|||
void CServer::DoSnapshot()
|
||||
{
|
||||
GameServer()->OnPreSnap();
|
||||
|
||||
|
||||
// create snapshot for demo recording
|
||||
if(m_DemoRecorder.IsRecording())
|
||||
{
|
||||
|
@ -462,7 +462,7 @@ void CServer::DoSnapshot()
|
|||
m_SnapshotBuilder.Init();
|
||||
GameServer()->OnSnap(-1);
|
||||
SnapshotSize = m_SnapshotBuilder.Finish(aData);
|
||||
|
||||
|
||||
// write snapshot
|
||||
m_DemoRecorder.RecordSnapshot(Tick(), aData, SnapshotSize);
|
||||
}
|
||||
|
@ -473,15 +473,15 @@ void CServer::DoSnapshot()
|
|||
// client must be ingame to recive snapshots
|
||||
if(m_aClients[i].m_State != CClient::STATE_INGAME)
|
||||
continue;
|
||||
|
||||
|
||||
// this client is trying to recover, don't spam snapshots
|
||||
if(m_aClients[i].m_SnapRate == CClient::SNAPRATE_RECOVER && (Tick()%50) != 0)
|
||||
continue;
|
||||
|
||||
|
||||
// this client is trying to recover, don't spam snapshots
|
||||
if(m_aClients[i].m_SnapRate == CClient::SNAPRATE_INIT && (Tick()%10) != 0)
|
||||
continue;
|
||||
|
||||
|
||||
{
|
||||
char aData[CSnapshot::MAX_SIZE];
|
||||
CSnapshot *pData = (CSnapshot*)aData; // Fix compiler warning for strict-aliasing
|
||||
|
@ -506,13 +506,13 @@ void CServer::DoSnapshot()
|
|||
// remove old snapshos
|
||||
// keep 3 seconds worth of snapshots
|
||||
m_aClients[i].m_Snapshots.PurgeUntil(m_CurrentGameTick-SERVER_TICK_SPEED*3);
|
||||
|
||||
|
||||
// save it the snapshot
|
||||
m_aClients[i].m_Snapshots.Add(m_CurrentGameTick, time_get(), SnapshotSize, pData, 0);
|
||||
|
||||
|
||||
// find snapshot that we can preform delta against
|
||||
EmptySnap.Clear();
|
||||
|
||||
|
||||
{
|
||||
DeltashotSize = m_aClients[i].m_Snapshots.Get(m_aClients[i].m_LastAckedSnapshot, 0, &pDeltashot, 0);
|
||||
if(DeltashotSize >= 0)
|
||||
|
@ -524,10 +524,10 @@ void CServer::DoSnapshot()
|
|||
m_aClients[i].m_SnapRate = CClient::SNAPRATE_RECOVER;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// create delta
|
||||
DeltaSize = m_SnapshotDelta.CreateDelta(pDeltashot, pData, aDeltaData);
|
||||
|
||||
|
||||
if(DeltaSize)
|
||||
{
|
||||
// compress it
|
||||
|
@ -537,7 +537,7 @@ void CServer::DoSnapshot()
|
|||
|
||||
SnapshotSize = CVariableInt::Compress(aDeltaData, DeltaSize, aCompData);
|
||||
NumPackets = (SnapshotSize+MaxSize-1)/MaxSize;
|
||||
|
||||
|
||||
for(int n = 0, Left = SnapshotSize; Left; n++)
|
||||
{
|
||||
int Chunk = Left < MaxSize ? Left : MaxSize;
|
||||
|
@ -559,7 +559,7 @@ void CServer::DoSnapshot()
|
|||
Msg.AddInt(m_CurrentGameTick);
|
||||
Msg.AddInt(m_CurrentGameTick-DeltaTick);
|
||||
Msg.AddInt(NumPackets);
|
||||
Msg.AddInt(n);
|
||||
Msg.AddInt(n);
|
||||
Msg.AddInt(Crc);
|
||||
Msg.AddInt(Chunk);
|
||||
Msg.AddRaw(&aCompData[n*MaxSize], Chunk);
|
||||
|
@ -598,7 +598,7 @@ int CServer::NewClientCallback(int ClientID, void *pUser)
|
|||
int CServer::DelClientCallback(int ClientID, const char *pReason, void *pUser)
|
||||
{
|
||||
CServer *pThis = (CServer *)pUser;
|
||||
|
||||
|
||||
NETADDR Addr = pThis->m_NetServer.ClientAddr(ClientID);
|
||||
char aAddrStr[NETADDR_MAXSTRSIZE];
|
||||
net_addr_str(&Addr, aAddrStr, sizeof(aAddrStr));
|
||||
|
@ -609,7 +609,7 @@ int CServer::DelClientCallback(int ClientID, const char *pReason, void *pUser)
|
|||
// notify the mod about the drop
|
||||
if(pThis->m_aClients[ClientID].m_State >= CClient::STATE_READY)
|
||||
pThis->GameServer()->OnClientDrop(ClientID, pReason);
|
||||
|
||||
|
||||
pThis->m_aClients[ClientID].m_State = CClient::STATE_EMPTY;
|
||||
pThis->m_aClients[ClientID].m_aName[0] = 0;
|
||||
pThis->m_aClients[ClientID].m_aClan[0] = 0;
|
||||
|
@ -649,16 +649,16 @@ void CServer::SendRconLineAuthed(const char *pLine, void *pUser)
|
|||
CServer *pThis = (CServer *)pUser;
|
||||
static volatile int ReentryGuard = 0;
|
||||
int i;
|
||||
|
||||
|
||||
if(ReentryGuard) return;
|
||||
ReentryGuard++;
|
||||
|
||||
|
||||
for(i = 0; i < MAX_CLIENTS; i++)
|
||||
{
|
||||
if(pThis->m_aClients[i].m_State != CClient::STATE_EMPTY && pThis->m_aClients[i].m_Authed)
|
||||
pThis->SendRconLine(i, pLine);
|
||||
}
|
||||
|
||||
|
||||
ReentryGuard--;
|
||||
}
|
||||
|
||||
|
@ -668,15 +668,15 @@ void CServer::ProcessClientPacket(CNetChunk *pPacket)
|
|||
NETADDR Addr;
|
||||
CUnpacker Unpacker;
|
||||
Unpacker.Reset(pPacket->m_pData, pPacket->m_DataSize);
|
||||
|
||||
|
||||
// unpack msgid and system flag
|
||||
int Msg = Unpacker.GetInt();
|
||||
int Sys = Msg&1;
|
||||
Msg >>= 1;
|
||||
|
||||
|
||||
if(Unpacker.Error())
|
||||
return;
|
||||
|
||||
|
||||
if(Sys)
|
||||
{
|
||||
// system message
|
||||
|
@ -693,7 +693,7 @@ void CServer::ProcessClientPacket(CNetChunk *pPacket)
|
|||
m_NetServer.Drop(ClientID, aReason);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
const char *pPassword = Unpacker.GetString(CUnpacker::SANITIZE_CC);
|
||||
if(g_Config.m_Password[0] != 0 && str_comp(g_Config.m_Password, pPassword) != 0)
|
||||
{
|
||||
|
@ -708,7 +708,7 @@ void CServer::ProcessClientPacket(CNetChunk *pPacket)
|
|||
m_NetServer.Drop(ClientID, "This server is full");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
m_aClients[ClientID].m_State = CClient::STATE_CONNECTING;
|
||||
SendMap(ClientID);
|
||||
}
|
||||
|
@ -719,11 +719,11 @@ void CServer::ProcessClientPacket(CNetChunk *pPacket)
|
|||
int ChunkSize = 1024-128;
|
||||
int Offset = Chunk * ChunkSize;
|
||||
int Last = 0;
|
||||
|
||||
|
||||
// drop faulty map data requests
|
||||
if(Chunk < 0 || Offset > m_CurrentMapSize)
|
||||
return;
|
||||
|
||||
|
||||
if(Offset+ChunkSize >= m_CurrentMapSize)
|
||||
{
|
||||
ChunkSize = m_CurrentMapSize-Offset;
|
||||
|
@ -731,7 +731,7 @@ void CServer::ProcessClientPacket(CNetChunk *pPacket)
|
|||
ChunkSize = 0;
|
||||
Last = 1;
|
||||
}
|
||||
|
||||
|
||||
CMsgPacker Msg(NETMSG_MAP_DATA);
|
||||
Msg.AddInt(Last);
|
||||
Msg.AddInt(m_CurrentMapCrc);
|
||||
|
@ -739,7 +739,7 @@ void CServer::ProcessClientPacket(CNetChunk *pPacket)
|
|||
Msg.AddInt(ChunkSize);
|
||||
Msg.AddRaw(&m_pCurrentMapData[Offset], ChunkSize);
|
||||
SendMsgEx(&Msg, MSGFLAG_VITAL|MSGFLAG_FLUSH, ClientID, true);
|
||||
|
||||
|
||||
if(g_Config.m_Debug)
|
||||
{
|
||||
char aBuf[256];
|
||||
|
@ -754,7 +754,7 @@ void CServer::ProcessClientPacket(CNetChunk *pPacket)
|
|||
Addr = m_NetServer.ClientAddr(ClientID);
|
||||
char aAddrStr[NETADDR_MAXSTRSIZE];
|
||||
net_addr_str(&Addr, aAddrStr, sizeof(aAddrStr));
|
||||
|
||||
|
||||
char aBuf[256];
|
||||
str_format(aBuf, sizeof(aBuf), "player is ready. ClientID=%x addr=%s", ClientID, aAddrStr);
|
||||
Console()->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "server", aBuf);
|
||||
|
@ -772,7 +772,7 @@ void CServer::ProcessClientPacket(CNetChunk *pPacket)
|
|||
m_aClients[ClientID].m_Addr = Addr;
|
||||
char aAddrStr[NETADDR_MAXSTRSIZE];
|
||||
net_addr_str(&Addr, aAddrStr, sizeof(aAddrStr));
|
||||
|
||||
|
||||
char aBuf[256];
|
||||
str_format(aBuf, sizeof(aBuf), "player has entered the game. ClientID=%x addr=%s", ClientID, aAddrStr);
|
||||
Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "server", aBuf);
|
||||
|
@ -784,18 +784,18 @@ void CServer::ProcessClientPacket(CNetChunk *pPacket)
|
|||
{
|
||||
CClient::CInput *pInput;
|
||||
int64 TagTime;
|
||||
|
||||
|
||||
m_aClients[ClientID].m_LastAckedSnapshot = Unpacker.GetInt();
|
||||
int IntendedTick = Unpacker.GetInt();
|
||||
int Size = Unpacker.GetInt();
|
||||
|
||||
|
||||
// check for errors
|
||||
if(Unpacker.Error() || Size/4 > MAX_INPUT_SIZE)
|
||||
return;
|
||||
|
||||
if(m_aClients[ClientID].m_LastAckedSnapshot > 0)
|
||||
m_aClients[ClientID].m_SnapRate = CClient::SNAPRATE_FULL;
|
||||
|
||||
|
||||
if(m_aClients[ClientID].m_Snapshots.Get(m_aClients[ClientID].m_LastAckedSnapshot, &TagTime, 0, 0) >= 0)
|
||||
m_aClients[ClientID].m_Latency = (int)(((time_get()-TagTime)*1000)/time_freq());
|
||||
|
||||
|
@ -804,7 +804,7 @@ void CServer::ProcessClientPacket(CNetChunk *pPacket)
|
|||
if(IntendedTick > m_aClients[ClientID].m_LastInputTick)
|
||||
{
|
||||
int TimeLeft = ((TickStartTime(IntendedTick)-time_get())*1000) / time_freq();
|
||||
|
||||
|
||||
CMsgPacker Msg(NETMSG_INPUTTIMING);
|
||||
Msg.AddInt(IntendedTick);
|
||||
Msg.AddInt(TimeLeft);
|
||||
|
@ -814,20 +814,20 @@ void CServer::ProcessClientPacket(CNetChunk *pPacket)
|
|||
m_aClients[ClientID].m_LastInputTick = IntendedTick;
|
||||
|
||||
pInput = &m_aClients[ClientID].m_aInputs[m_aClients[ClientID].m_CurrentInput];
|
||||
|
||||
|
||||
if(IntendedTick <= Tick())
|
||||
IntendedTick = Tick()+1;
|
||||
|
||||
pInput->m_GameTick = IntendedTick;
|
||||
|
||||
|
||||
for(int i = 0; i < Size/4; i++)
|
||||
pInput->m_aData[i] = Unpacker.GetInt();
|
||||
|
||||
|
||||
mem_copy(m_aClients[ClientID].m_LatestInput.m_aData, pInput->m_aData, MAX_INPUT_SIZE*sizeof(int));
|
||||
|
||||
|
||||
m_aClients[ClientID].m_CurrentInput++;
|
||||
m_aClients[ClientID].m_CurrentInput %= 200;
|
||||
|
||||
|
||||
// call the mod with the fresh input data
|
||||
if(m_aClients[ClientID].m_State == CClient::STATE_INGAME)
|
||||
GameServer()->OnClientDirectInput(ClientID, m_aClients[ClientID].m_LatestInput.m_aData);
|
||||
|
@ -835,7 +835,7 @@ void CServer::ProcessClientPacket(CNetChunk *pPacket)
|
|||
else if(Msg == NETMSG_RCON_CMD)
|
||||
{
|
||||
const char *pCmd = Unpacker.GetString();
|
||||
|
||||
|
||||
/*if(Unpacker.Error() == 0 && m_aClients[ClientID].m_Authed)
|
||||
{
|
||||
char aBuf[256];
|
||||
|
@ -870,7 +870,7 @@ void CServer::ProcessClientPacket(CNetChunk *pPacket)
|
|||
|
||||
if(Unpacker.Error() == 0)
|
||||
CheckPass(ClientID,pPw);
|
||||
|
||||
|
||||
/*if(Unpacker.Error() == 0)
|
||||
{
|
||||
if(g_Config.m_SvRconPassword[0] == 0)
|
||||
|
@ -882,7 +882,7 @@ void CServer::ProcessClientPacket(CNetChunk *pPacket)
|
|||
CMsgPacker Msg(NETMSG_RCON_AUTH_STATUS);
|
||||
Msg.AddInt(1);
|
||||
SendMsgEx(&Msg, MSGFLAG_VITAL, ClientID, true);
|
||||
|
||||
|
||||
m_aClients[ClientID].m_Authed = 1;
|
||||
SendRconLine(ClientID, "Authentication successful. Remote console access granted.");
|
||||
char aBuf[256];
|
||||
|
@ -946,7 +946,7 @@ void CServer::ProcessClientPacket(CNetChunk *pPacket)
|
|||
GameServer()->OnMessage(Msg, &Unpacker, ClientID);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void CServer::SendServerInfo(NETADDR *pAddr, int Token)
|
||||
{
|
||||
CNetChunk Packet;
|
||||
|
@ -961,17 +961,17 @@ void CServer::SendServerInfo(NETADDR *pAddr, int Token)
|
|||
{
|
||||
if(GameServer()->IsClientPlayer(i))
|
||||
PlayerCount++;
|
||||
|
||||
|
||||
ClientCount++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
p.Reset();
|
||||
|
||||
p.AddRaw(SERVERBROWSE_INFO, sizeof(SERVERBROWSE_INFO));
|
||||
str_format(aBuf, sizeof(aBuf), "%d", Token);
|
||||
p.AddString(aBuf, 6);
|
||||
|
||||
|
||||
p.AddString(GameServer()->Version(), 32);
|
||||
p.AddString(g_Config.m_SvName, 64);
|
||||
p.AddString(GetMapName(), 32);
|
||||
|
@ -981,28 +981,28 @@ void CServer::SendServerInfo(NETADDR *pAddr, int Token)
|
|||
|
||||
// flags
|
||||
int i = 0;
|
||||
if(g_Config.m_Password[0]) // password set
|
||||
if(g_Config.m_Password[0]) // password set
|
||||
i |= SERVER_FLAG_PASSWORD;
|
||||
str_format(aBuf, sizeof(aBuf), "%d", i);
|
||||
p.AddString(aBuf, 2);
|
||||
|
||||
str_format(aBuf, sizeof(aBuf), "%d", PlayerCount); p.AddString(aBuf, 3); // num players
|
||||
str_format(aBuf, sizeof(aBuf), "%d", PlayerCount); p.AddString(aBuf, 3); // num players
|
||||
str_format(aBuf, sizeof(aBuf), "%d", m_NetServer.MaxClients()-g_Config.m_SvSpectatorSlots-g_Config.m_SvReservedSlots); p.AddString(aBuf, 3); // max players
|
||||
str_format(aBuf, sizeof(aBuf), "%d", ClientCount); p.AddString(aBuf, 3); // num clients
|
||||
str_format(aBuf, sizeof(aBuf), "%d", ClientCount); p.AddString(aBuf, 3); // num clients
|
||||
str_format(aBuf, sizeof(aBuf), "%d", m_NetServer.MaxClients()); p.AddString(aBuf, 3); // max clients
|
||||
|
||||
for(i = 0; i < MAX_CLIENTS; i++)
|
||||
{
|
||||
if(m_aClients[i].m_State != CClient::STATE_EMPTY)
|
||||
{
|
||||
p.AddString(ClientName(i), MAX_NAME_LENGTH); // client name
|
||||
p.AddString(ClientClan(i), MAX_CLAN_LENGTH); // client clan
|
||||
str_format(aBuf, sizeof(aBuf), "%d", m_aClients[i].m_Country); p.AddString(aBuf, 6); // client country
|
||||
str_format(aBuf, sizeof(aBuf), "%d", m_aClients[i].m_Score); p.AddString(aBuf, 6); // client score
|
||||
str_format(aBuf, sizeof(aBuf), "%d", GameServer()->IsClientPlayer(i)?1:0); p.AddString(aBuf, 2); // is player?
|
||||
p.AddString(ClientName(i), MAX_NAME_LENGTH); // client name
|
||||
p.AddString(ClientClan(i), MAX_CLAN_LENGTH); // client clan
|
||||
str_format(aBuf, sizeof(aBuf), "%d", m_aClients[i].m_Country); p.AddString(aBuf, 6); // client country
|
||||
str_format(aBuf, sizeof(aBuf), "%d", m_aClients[i].m_Score); p.AddString(aBuf, 6); // client score
|
||||
str_format(aBuf, sizeof(aBuf), "%d", GameServer()->IsClientPlayer(i)?1:0); p.AddString(aBuf, 2); // is player?
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Packet.m_ClientID = -1;
|
||||
Packet.m_Address = *pAddr;
|
||||
Packet.m_Flags = NETSENDFLAG_CONNLESS;
|
||||
|
@ -1035,21 +1035,21 @@ int CServer::BanAdd(NETADDR Addr, int Seconds, const char *pReason)
|
|||
str_format(aBuf, sizeof(aBuf), "banned %s for life", aAddrStr);
|
||||
Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "server", aBuf);
|
||||
|
||||
return m_NetServer.BanAdd(Addr, Seconds, pReason);
|
||||
return m_NetServer.BanAdd(Addr, Seconds, pReason);
|
||||
}
|
||||
|
||||
int CServer::BanRemove(NETADDR Addr)
|
||||
{
|
||||
return m_NetServer.BanRemove(Addr);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void CServer::PumpNetwork()
|
||||
{
|
||||
CNetChunk Packet;
|
||||
|
||||
m_NetServer.Update();
|
||||
|
||||
|
||||
// process packets
|
||||
while(m_NetServer.Recv(&Packet))
|
||||
{
|
||||
|
@ -1117,7 +1117,7 @@ int CServer::LoadMap(const char *pMapName)
|
|||
//DATAFILE *df;
|
||||
char aBuf[512];
|
||||
str_format(aBuf, sizeof(aBuf), "maps/%s.map", pMapName);
|
||||
|
||||
|
||||
/*df = datafile_load(buf);
|
||||
if(!df)
|
||||
return 0;*/
|
||||
|
@ -1128,25 +1128,25 @@ int CServer::LoadMap(const char *pMapName)
|
|||
Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "mapchecker", "invalid standard map");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
if(!m_pMap->Load(aBuf))
|
||||
return 0;
|
||||
|
||||
|
||||
// stop recording when we change map
|
||||
m_DemoRecorder.Stop();
|
||||
|
||||
|
||||
// reinit snapshot ids
|
||||
m_IDPool.TimeoutIDs();
|
||||
|
||||
|
||||
// get the crc of the map
|
||||
m_CurrentMapCrc = m_pMap->Crc();
|
||||
char aBufMsg[256];
|
||||
str_format(aBufMsg, sizeof(aBufMsg), "%s crc is %08x", aBuf, m_CurrentMapCrc);
|
||||
Console()->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "server", aBufMsg);
|
||||
|
||||
|
||||
str_copy(m_aCurrentMap, pMapName, sizeof(m_aCurrentMap));
|
||||
//map_set(df);
|
||||
|
||||
|
||||
// load compelate map into memory for download
|
||||
{
|
||||
IOHANDLE File = Storage()->OpenFile(aBuf, IOFLAG_READ, IStorage::TYPE_ALL);
|
||||
|
@ -1186,7 +1186,7 @@ int CServer::Run()
|
|||
dbg_msg("server", "failed to load map. mapname='%s'", g_Config.m_SvMap);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
// start server
|
||||
NETADDR BindAddr;
|
||||
if(g_Config.m_SvBindaddr[0] && net_host_lookup(g_Config.m_SvBindaddr, &BindAddr, NETTYPE_ALL) == 0)
|
||||
|
@ -1200,8 +1200,8 @@ int CServer::Run()
|
|||
BindAddr.type = NETTYPE_ALL;
|
||||
BindAddr.port = g_Config.m_SvPort;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
if(!m_NetServer.Open(BindAddr, g_Config.m_SvMaxClients, g_Config.m_SvMaxClientsPerIP, 0))
|
||||
{
|
||||
dbg_msg("server", "couldn't open socket. port might already be in use");
|
||||
|
@ -1210,11 +1210,11 @@ int CServer::Run()
|
|||
|
||||
m_NetServer.SetCallbacks(NewClientCallback, DelClientCallback, this);
|
||||
Console()->ExecuteFile(SERVER_BANMASTERFILE, -1, IConsole::CONSOLELEVEL_CONFIG, 0, 0);
|
||||
|
||||
|
||||
char aBuf[256];
|
||||
str_format(aBuf, sizeof(aBuf), "server name is '%s'", g_Config.m_SvName);
|
||||
Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "server", aBuf);
|
||||
|
||||
|
||||
GameServer()->OnInit();
|
||||
str_format(aBuf, sizeof(aBuf), "version %s", GameServer()->NetVersion());
|
||||
Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "server", aBuf);
|
||||
|
@ -1226,10 +1226,10 @@ int CServer::Run()
|
|||
{
|
||||
int64 ReportTime = time_get();
|
||||
int ReportInterval = 3;
|
||||
|
||||
|
||||
m_Lastheartbeat = 0;
|
||||
m_GameStartTime = time_get();
|
||||
|
||||
|
||||
if(g_Config.m_Debug)
|
||||
{
|
||||
str_format(aBuf, sizeof(aBuf), "baseline memory usage %dk", mem_stats()->allocated/1024);
|
||||
|
@ -1240,28 +1240,28 @@ int CServer::Run()
|
|||
{
|
||||
int64 t = time_get();
|
||||
int NewTicks = 0;
|
||||
|
||||
|
||||
// load new map TODO: don't poll this
|
||||
if(str_comp(g_Config.m_SvMap, m_aCurrentMap) != 0 || m_MapReload)
|
||||
{
|
||||
m_MapReload = 0;
|
||||
|
||||
|
||||
// load map
|
||||
if(LoadMap(g_Config.m_SvMap))
|
||||
{
|
||||
// new map loaded
|
||||
GameServer()->OnShutdown();
|
||||
|
||||
|
||||
for(int c = 0; c < MAX_CLIENTS; c++)
|
||||
{
|
||||
if(m_aClients[c].m_State <= CClient::STATE_AUTH)
|
||||
continue;
|
||||
|
||||
|
||||
SendMap(c);
|
||||
m_aClients[c].Reset();
|
||||
m_aClients[c].m_State = CClient::STATE_CONNECTING;
|
||||
}
|
||||
|
||||
|
||||
m_GameStartTime = time_get();
|
||||
m_CurrentGameTick = 0;
|
||||
Kernel()->ReregisterInterface(GameServer());
|
||||
|
@ -1275,12 +1275,12 @@ int CServer::Run()
|
|||
str_copy(g_Config.m_SvMap, m_aCurrentMap, sizeof(g_Config.m_SvMap));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
while(t > TickStartTime(m_CurrentGameTick+1))
|
||||
{
|
||||
m_CurrentGameTick++;
|
||||
NewTicks++;
|
||||
|
||||
|
||||
// apply new input
|
||||
for(int c = 0; c < MAX_CLIENTS; c++)
|
||||
{
|
||||
|
@ -1299,19 +1299,19 @@ int CServer::Run()
|
|||
|
||||
GameServer()->OnTick();
|
||||
}
|
||||
|
||||
|
||||
// snap game
|
||||
if(NewTicks)
|
||||
{
|
||||
if(g_Config.m_SvHighBandwidth || (m_CurrentGameTick%2) == 0)
|
||||
DoSnapshot();
|
||||
}
|
||||
|
||||
|
||||
// master server stuff
|
||||
m_Register.RegisterUpdate(BindAddr.type);
|
||||
|
||||
|
||||
PumpNetwork();
|
||||
|
||||
|
||||
if(ReportTime < time_get())
|
||||
{
|
||||
if(g_Config.m_Debug)
|
||||
|
@ -1320,23 +1320,23 @@ int CServer::Run()
|
|||
static NETSTATS prev_stats;
|
||||
NETSTATS stats;
|
||||
netserver_stats(net, &stats);
|
||||
|
||||
|
||||
perf_next();
|
||||
|
||||
|
||||
if(config.dbg_pref)
|
||||
perf_dump(&rootscope);
|
||||
|
||||
dbg_msg("server", "send=%8d recv=%8d",
|
||||
(stats.send_bytes - prev_stats.send_bytes)/reportinterval,
|
||||
(stats.recv_bytes - prev_stats.recv_bytes)/reportinterval);
|
||||
|
||||
|
||||
prev_stats = stats;
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
ReportTime += time_freq()*ReportInterval;
|
||||
}
|
||||
|
||||
|
||||
// wait for incomming data
|
||||
net_socket_read_wait(m_NetServer.Socket(), 5);
|
||||
}
|
||||
|
@ -1375,14 +1375,14 @@ void CServer::ConBan(IConsole::IResult *pResult, void *pUser, int ClientID)
|
|||
CServer *pServer = (CServer *)pUser;
|
||||
const char *pStr = pResult->GetString(0);
|
||||
int Minutes = 30;
|
||||
const char *pReason = "No reason given";
|
||||
|
||||
const char *pReason = "No reason given";
|
||||
|
||||
if(pResult->NumArguments() > 1)
|
||||
Minutes = pResult->GetInteger(1);
|
||||
|
||||
|
||||
if(pResult->NumArguments() > 2)
|
||||
pReason = pResult->GetString(2);
|
||||
|
||||
|
||||
if(net_addr_from_str(&Addr, pStr) == 0)
|
||||
{
|
||||
if(pServer->m_RconClientID >= 0 && pServer->m_RconClientID < MAX_CLIENTS && pServer->m_aClients[pServer->m_RconClientID].m_State != CClient::STATE_EMPTY)
|
||||
|
@ -1429,7 +1429,7 @@ void CServer::ConUnban(IConsole::IResult *pResult, void *pUser, int ClientID)
|
|||
NETADDR Addr;
|
||||
CServer *pServer = (CServer *)pUser;
|
||||
const char *pStr = pResult->GetString(0);
|
||||
|
||||
|
||||
if(net_addr_from_str(&Addr, pStr) == 0 && !pServer->BanRemove(Addr))
|
||||
{
|
||||
char aAddrStr[NETADDR_MAXSTRSIZE];
|
||||
|
@ -1465,7 +1465,7 @@ void CServer::ConBans(IConsole::IResult *pResult, void *pUser, int ClientID)
|
|||
char aBuf[1024];
|
||||
char aAddrStr[NETADDR_MAXSTRSIZE];
|
||||
CServer* pServer = (CServer *)pUser;
|
||||
|
||||
|
||||
int Num = pServer->m_NetServer.BanNum();
|
||||
for(int i = 0; i < Num; i++)
|
||||
{
|
||||
|
@ -1473,7 +1473,7 @@ void CServer::ConBans(IConsole::IResult *pResult, void *pUser, int ClientID)
|
|||
pServer->m_NetServer.BanGet(i, &Info);
|
||||
NETADDR Addr = Info.m_Addr;
|
||||
net_addr_str(&Addr, aAddrStr, sizeof(aAddrStr));
|
||||
|
||||
|
||||
if(Info.m_Expires == -1)
|
||||
{
|
||||
str_format(aBuf, sizeof(aBuf), "#%i %s for life", i, aAddrStr);
|
||||
|
@ -1561,7 +1561,7 @@ void CServer::ConchainMaxclientsperipUpdate(IConsole::IResult *pResult, void *pU
|
|||
void CServer::RegisterCommands()
|
||||
{
|
||||
m_pConsole = Kernel()->RequestInterface<IConsole>();
|
||||
|
||||
|
||||
Console()->Register("kick", "v?r", CFGFLAG_SERVER, ConKick, this, "", IConsole::CONSOLELEVEL_MODERATOR);
|
||||
Console()->Register("ban", "s?ir", CFGFLAG_SERVER|CFGFLAG_STORE, ConBan, this, "", IConsole::CONSOLELEVEL_MODERATOR);
|
||||
Console()->Register("unban", "s", CFGFLAG_SERVER|CFGFLAG_STORE, ConUnban, this, "", IConsole::CONSOLELEVEL_MODERATOR);
|
||||
|
@ -1571,7 +1571,7 @@ void CServer::RegisterCommands()
|
|||
|
||||
Console()->Register("record", "?s", CFGFLAG_SERVER|CFGFLAG_STORE, ConRecord, this, "", IConsole::CONSOLELEVEL_ADMIN);
|
||||
Console()->Register("stoprecord", "", CFGFLAG_SERVER, ConStopRecord, this, "", IConsole::CONSOLELEVEL_ADMIN);
|
||||
|
||||
|
||||
Console()->Register("reload", "", CFGFLAG_SERVER, ConMapReload, this, "", IConsole::CONSOLELEVEL_ADMIN);
|
||||
|
||||
Console()->Chain("sv_name", ConchainSpecialInfoupdate, this);
|
||||
|
@ -1585,7 +1585,7 @@ void CServer::RegisterCommands()
|
|||
Console()->Register("login", "?s", CFGFLAG_SERVER, ConLogin, this, "Allows you access to rcon if no password is given, or changes your level if a password is given", IConsole::CONSOLELEVEL_USER);
|
||||
Console()->Register("auth", "?s", CFGFLAG_SERVER, ConLogin, this, "Allows you access to rcon if no password is given, or changes your level if a password is given", IConsole::CONSOLELEVEL_USER);
|
||||
Console()->Register("cmdlist", "?i", CFGFLAG_SERVER, ConCmdList, this, "Shows you the commands available for your remote console access. Specify the level if you want to see other level's commands", IConsole::CONSOLELEVEL_USER);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int CServer::SnapNewID()
|
||||
|
@ -1603,7 +1603,7 @@ void *CServer::SnapNewItem(int Type, int ID, int Size)
|
|||
{
|
||||
dbg_assert(Type >= 0 && Type <=0xffff, "incorrect type");
|
||||
dbg_assert(ID >= 0 && ID <=0xffff, "incorrect id");
|
||||
return ID < 0 ? 0 : m_SnapshotBuilder.NewItem(Type, ID, Size);
|
||||
return ID < 0 ? 0 : m_SnapshotBuilder.NewItem(Type, ID, Size);
|
||||
}
|
||||
|
||||
void CServer::SnapSetStaticsize(int ItemType, int Size)
|
||||
|
@ -1637,7 +1637,7 @@ int main(int argc, const char **argv) // ignore_convention
|
|||
IEngineMasterServer *pEngineMasterServer = CreateEngineMasterServer();
|
||||
IStorage *pStorage = CreateStorage("Teeworlds", argc, argv); // ignore_convention
|
||||
IConfig *pConfig = CreateConfig();
|
||||
|
||||
|
||||
pServer->InitRegister(&pServer->m_NetServer, pEngineMasterServer, pConsole);
|
||||
|
||||
{
|
||||
|
@ -1653,20 +1653,20 @@ int main(int argc, const char **argv) // ignore_convention
|
|||
RegisterFail = RegisterFail || !pKernel->RegisterInterface(pConfig);
|
||||
RegisterFail = RegisterFail || !pKernel->RegisterInterface(static_cast<IEngineMasterServer*>(pEngineMasterServer)); // register as both
|
||||
RegisterFail = RegisterFail || !pKernel->RegisterInterface(static_cast<IMasterServer*>(pEngineMasterServer));
|
||||
|
||||
|
||||
if(RegisterFail)
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
pEngine->Init();
|
||||
pConfig->Init();
|
||||
pEngineMasterServer->Init();
|
||||
pEngineMasterServer->Load();
|
||||
|
||||
|
||||
// register all console commands
|
||||
pServer->RegisterCommands();
|
||||
pGameServer->OnConsoleInit();
|
||||
|
||||
|
||||
// execute autoexec file
|
||||
pConsole->ExecuteFile("autoexec.cfg", -1, IConsole::CONSOLELEVEL_CONFIG, 0, 0);
|
||||
|
||||
|
@ -1676,13 +1676,13 @@ int main(int argc, const char **argv) // ignore_convention
|
|||
|
||||
// restore empty config strings to their defaults
|
||||
pConfig->RestoreStrings();
|
||||
|
||||
|
||||
pEngine->InitLogfile();
|
||||
|
||||
// run the server
|
||||
dbg_msg("server", "starting...");
|
||||
pServer->Run();
|
||||
|
||||
|
||||
// free
|
||||
delete pServer;
|
||||
delete pKernel;
|
||||
|
|
|
@ -31,17 +31,17 @@ class CSnapIDPool
|
|||
};
|
||||
|
||||
CID m_aIDs[MAX_IDS];
|
||||
|
||||
|
||||
int m_FirstFree;
|
||||
int m_FirstTimed;
|
||||
int m_LastTimed;
|
||||
int m_Usage;
|
||||
int m_InUsage;
|
||||
|
||||
public:
|
||||
|
||||
public:
|
||||
|
||||
CSnapIDPool();
|
||||
|
||||
|
||||
void Reset();
|
||||
void RemoveFirstTimeout();
|
||||
int NewID();
|
||||
|
@ -62,7 +62,7 @@ public:
|
|||
class CClient
|
||||
{
|
||||
public:
|
||||
|
||||
|
||||
enum
|
||||
{
|
||||
STATE_EMPTY = 0,
|
||||
|
@ -70,53 +70,53 @@ public:
|
|||
STATE_CONNECTING,
|
||||
STATE_READY,
|
||||
STATE_INGAME,
|
||||
|
||||
|
||||
SNAPRATE_INIT=0,
|
||||
SNAPRATE_FULL,
|
||||
SNAPRATE_RECOVER
|
||||
};
|
||||
|
||||
|
||||
class CInput
|
||||
{
|
||||
public:
|
||||
int m_aData[MAX_INPUT_SIZE];
|
||||
int m_GameTick; // the tick that was chosen for the input
|
||||
};
|
||||
|
||||
|
||||
// connection state info
|
||||
int m_State;
|
||||
int m_Latency;
|
||||
int m_SnapRate;
|
||||
|
||||
|
||||
int m_LastAckedSnapshot;
|
||||
int m_LastInputTick;
|
||||
CSnapshotStorage m_Snapshots;
|
||||
|
||||
|
||||
CInput m_LatestInput;
|
||||
CInput m_aInputs[200]; // TODO: handle input better
|
||||
int m_CurrentInput;
|
||||
|
||||
|
||||
char m_aName[MAX_NAME_LENGTH];
|
||||
char m_aClan[MAX_CLAN_LENGTH];
|
||||
int m_Country;
|
||||
int m_Score;
|
||||
int m_Authed;
|
||||
int m_AuthTries;
|
||||
|
||||
|
||||
void Reset();
|
||||
|
||||
// DDRace
|
||||
|
||||
NETADDR m_Addr;
|
||||
};
|
||||
|
||||
|
||||
CClient m_aClients[MAX_CLIENTS];
|
||||
|
||||
CSnapshotDelta m_SnapshotDelta;
|
||||
CSnapshotBuilder m_SnapshotBuilder;
|
||||
CSnapIDPool m_IDPool;
|
||||
CNetServer m_NetServer;
|
||||
|
||||
|
||||
IEngineMap *m_pMap;
|
||||
|
||||
int64 m_GameStartTime;
|
||||
|
@ -131,14 +131,14 @@ public:
|
|||
char m_aCurrentMap[64];
|
||||
unsigned m_CurrentMapCrc;
|
||||
unsigned char *m_pCurrentMapData;
|
||||
int m_CurrentMapSize;
|
||||
|
||||
int m_CurrentMapSize;
|
||||
|
||||
CDemoRecorder m_DemoRecorder;
|
||||
CRegister m_Register;
|
||||
CMapChecker m_MapChecker;
|
||||
|
||||
|
||||
CServer();
|
||||
|
||||
|
||||
int TrySetClientName(int ClientID, const char *pName);
|
||||
|
||||
virtual void SetClientName(int ClientID, const char *pName);
|
||||
|
@ -176,15 +176,15 @@ public:
|
|||
void SendConnectionReady(int ClientID);
|
||||
void SendRconLine(int ClientID, const char *pLine);
|
||||
static void SendRconLineAuthed(const char *pLine, void *pUser);
|
||||
|
||||
|
||||
void ProcessClientPacket(CNetChunk *pPacket);
|
||||
|
||||
|
||||
void SendServerInfo(NETADDR *pAddr, int Token);
|
||||
void UpdateServerInfo();
|
||||
|
||||
int BanAdd(NETADDR Addr, int Seconds, const char *pReason);
|
||||
int BanRemove(NETADDR Addr);
|
||||
|
||||
|
||||
|
||||
void PumpNetwork();
|
||||
|
||||
|
@ -207,8 +207,8 @@ public:
|
|||
static void ConchainMaxclientsperipUpdate(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData);
|
||||
|
||||
void RegisterCommands();
|
||||
|
||||
|
||||
|
||||
|
||||
virtual int SnapNewID();
|
||||
virtual void SnapFreeID(int ID);
|
||||
virtual void *SnapNewItem(int Type, int ID, int Size);
|
||||
|
|
|
@ -28,11 +28,11 @@ public:
|
|||
|
||||
int m_SortedIndex;
|
||||
int m_ServerIndex;
|
||||
|
||||
|
||||
NETADDR m_NetAddr;
|
||||
|
||||
|
||||
int m_QuickSearchHit;
|
||||
|
||||
|
||||
int m_MaxClients;
|
||||
int m_NumClients;
|
||||
int m_MaxPlayers;
|
||||
|
@ -66,11 +66,11 @@ public:
|
|||
SORT_MAP,
|
||||
SORT_GAMETYPE,
|
||||
SORT_NUMPLAYERS,
|
||||
|
||||
|
||||
QUICK_SERVERNAME=1,
|
||||
QUICK_PLAYER=2,
|
||||
QUICK_MAPNAME=4,
|
||||
|
||||
|
||||
TYPE_INTERNET = 0,
|
||||
TYPE_LAN = 1,
|
||||
TYPE_FAVORITES = 2,
|
||||
|
@ -84,12 +84,12 @@ public:
|
|||
virtual bool IsRefreshing() const = 0;
|
||||
virtual bool IsRefreshingMasters() const = 0;
|
||||
virtual int LoadingProgression() const = 0;
|
||||
|
||||
|
||||
virtual int NumServers() const = 0;
|
||||
|
||||
|
||||
virtual int NumSortedServers() const = 0;
|
||||
virtual const CServerInfo *SortedGet(int Index) const = 0;
|
||||
|
||||
|
||||
virtual bool IsFavorite(const NETADDR &Addr) const = 0;
|
||||
virtual void AddFavorite(const NETADDR &Addr) = 0;
|
||||
virtual void RemoveFavorite(const NETADDR &Addr) = 0;
|
||||
|
|
|
@ -4,9 +4,9 @@
|
|||
|
||||
#include "compression.h"
|
||||
|
||||
// Format: ESDDDDDD EDDDDDDD EDD... Extended, Data, Sign
|
||||
unsigned char *CVariableInt::Pack(unsigned char *pDst, int i)
|
||||
{
|
||||
// Format: ESDDDDDD EDDDDDDD EDD... Extended, Data, Sign
|
||||
unsigned char *CVariableInt::Pack(unsigned char *pDst, int i)
|
||||
{
|
||||
*pDst = (i>>25)&0x40; // set sign bit if i<0
|
||||
i = i^(i>>31); // if(i<0) i = ~i
|
||||
|
||||
|
@ -27,16 +27,16 @@ unsigned char *CVariableInt::Pack(unsigned char *pDst, int i)
|
|||
}
|
||||
|
||||
pDst++;
|
||||
return pDst;
|
||||
}
|
||||
|
||||
return pDst;
|
||||
}
|
||||
|
||||
const unsigned char *CVariableInt::Unpack(const unsigned char *pSrc, int *pInOut)
|
||||
{
|
||||
int Sign = (*pSrc>>6)&1;
|
||||
*pInOut = *pSrc&0x3F;
|
||||
{
|
||||
int Sign = (*pSrc>>6)&1;
|
||||
*pInOut = *pSrc&0x3F;
|
||||
|
||||
do
|
||||
{
|
||||
{
|
||||
if(!(*pSrc&0x80)) break;
|
||||
pSrc++;
|
||||
*pInOut |= (*pSrc&(0x7F))<<(6);
|
||||
|
@ -56,8 +56,8 @@ const unsigned char *CVariableInt::Unpack(const unsigned char *pSrc, int *pInOut
|
|||
|
||||
pSrc++;
|
||||
*pInOut ^= -Sign; // if(sign) *i = ~(*i)
|
||||
return pSrc;
|
||||
}
|
||||
return pSrc;
|
||||
}
|
||||
|
||||
|
||||
long CVariableInt::Decompress(const void *pSrc_, int Size, void *pDst_)
|
||||
|
|
|
@ -13,21 +13,21 @@ class CConfig : public IConfig
|
|||
{
|
||||
IStorage *m_pStorage;
|
||||
IOHANDLE m_ConfigFile;
|
||||
|
||||
|
||||
struct CCallback
|
||||
{
|
||||
SAVECALLBACKFUNC m_pfnFunc;
|
||||
void *m_pUserData;
|
||||
};
|
||||
|
||||
|
||||
enum
|
||||
{
|
||||
MAX_CALLBACKS = 16
|
||||
};
|
||||
|
||||
|
||||
CCallback m_aCallbacks[MAX_CALLBACKS];
|
||||
int m_NumCallbacks;
|
||||
|
||||
|
||||
void EscapeParam(char *pDst, const char *pSrc, int size)
|
||||
{
|
||||
for(int i = 0; *pSrc && i < size - 1; ++i)
|
||||
|
@ -46,22 +46,22 @@ public:
|
|||
m_ConfigFile = 0;
|
||||
m_NumCallbacks = 0;
|
||||
}
|
||||
|
||||
|
||||
virtual void Init()
|
||||
{
|
||||
m_pStorage = Kernel()->RequestInterface<IStorage>();
|
||||
Reset();
|
||||
}
|
||||
|
||||
|
||||
virtual void Reset()
|
||||
{
|
||||
#define MACRO_CONFIG_INT(Name,ScriptName,def,min,max,flags,desc,Level) g_Config.m_##Name = def;
|
||||
#define MACRO_CONFIG_STR(Name,ScriptName,len,def,flags,desc,Level) str_copy(g_Config.m_##Name, def, len);
|
||||
|
||||
#include "config_variables.h"
|
||||
#include "config_variables.h"
|
||||
|
||||
#undef MACRO_CONFIG_INT
|
||||
#undef MACRO_CONFIG_STR
|
||||
#undef MACRO_CONFIG_INT
|
||||
#undef MACRO_CONFIG_STR
|
||||
}
|
||||
|
||||
virtual void RestoreStrings()
|
||||
|
@ -74,34 +74,34 @@ public:
|
|||
#undef MACRO_CONFIG_INT
|
||||
#undef MACRO_CONFIG_STR
|
||||
}
|
||||
|
||||
|
||||
virtual void Save()
|
||||
{
|
||||
if(!m_pStorage)
|
||||
return;
|
||||
m_ConfigFile = m_pStorage->OpenFile("settings.cfg", IOFLAG_WRITE, IStorage::TYPE_SAVE);
|
||||
|
||||
|
||||
if(!m_ConfigFile)
|
||||
return;
|
||||
|
||||
|
||||
char aLineBuf[1024*2];
|
||||
char aEscapeBuf[1024*2];
|
||||
|
||||
#define MACRO_CONFIG_INT(Name,ScriptName,def,min,max,flags,desc,Level) if((flags)&CFGFLAG_SAVE){ str_format(aLineBuf, sizeof(aLineBuf), "%s %i", #ScriptName, g_Config.m_##Name); WriteLine(aLineBuf); }
|
||||
#define MACRO_CONFIG_STR(Name,ScriptName,len,def,flags,desc,Level) if((flags)&CFGFLAG_SAVE){ EscapeParam(aEscapeBuf, g_Config.m_##Name, sizeof(aEscapeBuf)); str_format(aLineBuf, sizeof(aLineBuf), "%s \"%s\"", #ScriptName, aEscapeBuf); WriteLine(aLineBuf); }
|
||||
|
||||
#include "config_variables.h"
|
||||
#include "config_variables.h"
|
||||
|
||||
#undef MACRO_CONFIG_INT
|
||||
#undef MACRO_CONFIG_STR
|
||||
|
||||
#undef MACRO_CONFIG_INT
|
||||
#undef MACRO_CONFIG_STR
|
||||
|
||||
for(int i = 0; i < m_NumCallbacks; i++)
|
||||
m_aCallbacks[i].m_pfnFunc(this, m_aCallbacks[i].m_pUserData);
|
||||
|
||||
|
||||
io_close(m_ConfigFile);
|
||||
m_ConfigFile = 0;
|
||||
}
|
||||
|
||||
|
||||
virtual void RegisterCallback(SAVECALLBACKFUNC pfnFunc, void *pUserData)
|
||||
{
|
||||
dbg_assert(m_NumCallbacks < MAX_CALLBACKS, "too many config callbacks");
|
||||
|
@ -109,7 +109,7 @@ public:
|
|||
m_aCallbacks[m_NumCallbacks].m_pUserData = pUserData;
|
||||
m_NumCallbacks++;
|
||||
}
|
||||
|
||||
|
||||
virtual void WriteLine(const char *pLine)
|
||||
{
|
||||
if(!m_ConfigFile)
|
||||
|
@ -120,7 +120,7 @@ public:
|
|||
static const char Newline[] = "\n";
|
||||
#endif
|
||||
io_write(m_ConfigFile, pLine, str_length(pLine));
|
||||
io_write(m_ConfigFile, Newline, sizeof(Newline)-1);
|
||||
io_write(m_ConfigFile, Newline, sizeof(Newline)-1);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
|
||||
/* If you are missing that file, acquire a complete release at teeworlds.com. */
|
||||
#ifndef ENGINE_SHARED_E_CONFIG_H
|
||||
#define ENGINE_SHARED_E_CONFIG_H
|
||||
#ifndef ENGINE_SHARED_CONFIG_H
|
||||
#define ENGINE_SHARED_CONFIG_H
|
||||
|
||||
struct CConfiguration
|
||||
{
|
||||
#define MACRO_CONFIG_INT(Name,ScriptName,Def,Min,Max,Save,Desc,Level) int m_##Name;
|
||||
#define MACRO_CONFIG_STR(Name,ScriptName,Len,Def,Save,Desc,Level) char m_##Name[Len]; // Flawfinder: ignore
|
||||
#include "config_variables.h"
|
||||
#undef MACRO_CONFIG_INT
|
||||
#undef MACRO_CONFIG_STR
|
||||
{
|
||||
#define MACRO_CONFIG_INT(Name,ScriptName,Def,Min,Max,Save,Desc,Level) int m_##Name;
|
||||
#define MACRO_CONFIG_STR(Name,ScriptName,Len,Def,Save,Desc,Level) char m_##Name[Len]; // Flawfinder: ignore
|
||||
#include "config_variables.h"
|
||||
#undef MACRO_CONFIG_INT
|
||||
#undef MACRO_CONFIG_STR
|
||||
};
|
||||
|
||||
extern CConfiguration g_Config;
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
|
||||
/* If you are missing that file, acquire a complete release at teeworlds.com. */
|
||||
#ifndef ENGINE_SHARED_E_CONFIG_VARIABLES_H
|
||||
#define ENGINE_SHARED_E_CONFIG_VARIABLES_H
|
||||
#undef ENGINE_SHARED_E_CONFIG_VARIABLES_H // this file will be included several times
|
||||
#ifndef ENGINE_SHARED_CONFIG_VARIABLES_H
|
||||
#define ENGINE_SHARED_CONFIG_VARIABLES_H
|
||||
#undef ENGINE_SHARED_CONFIG_VARIABLES_H // this file will be included several times
|
||||
|
||||
// TODO: remove this
|
||||
#include "././game/variables.h"
|
||||
|
@ -47,6 +47,7 @@ MACRO_CONFIG_INT(BrMaxRequests, br_max_requests, 25, 0, 1000, CFGFLAG_SAVE|CFGFL
|
|||
MACRO_CONFIG_INT(SndBufferSize, snd_buffer_size, 512, 0, 0, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Sound buffer size", IConsole::CONSOLELEVEL_USER)
|
||||
MACRO_CONFIG_INT(SndRate, snd_rate, 48000, 0, 0, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Sound mixing rate", IConsole::CONSOLELEVEL_USER)
|
||||
MACRO_CONFIG_INT(SndEnable, snd_enable, 1, 0, 1, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Sound enable", IConsole::CONSOLELEVEL_USER)
|
||||
MACRO_CONFIG_INT(SndMusic, snd_enable_music, 1, 0, 1, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Play background music", IConsole::CONSOLELEVEL_USER)
|
||||
MACRO_CONFIG_INT(SndVolume, snd_volume, 100, 0, 100, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Sound volume", IConsole::CONSOLELEVEL_USER)
|
||||
MACRO_CONFIG_INT(SndDevice, snd_device, -1, 0, 0, CFGFLAG_SAVE|CFGFLAG_CLIENT, "(deprecated) Sound device to use", IConsole::CONSOLELEVEL_USER)
|
||||
|
||||
|
@ -55,7 +56,7 @@ MACRO_CONFIG_INT(SndNonactiveMute, snd_nonactive_mute, 0, 0, 1, CFGFLAG_SAVE|CFG
|
|||
MACRO_CONFIG_INT(GfxScreenWidth, gfx_screen_width, 800, 0, 0, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Screen resolution width", IConsole::CONSOLELEVEL_USER)
|
||||
MACRO_CONFIG_INT(GfxScreenHeight, gfx_screen_height, 600, 0, 0, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Screen resolution height", IConsole::CONSOLELEVEL_USER)
|
||||
MACRO_CONFIG_INT(GfxFullscreen, gfx_fullscreen, 1, 0, 1, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Fullscreen", IConsole::CONSOLELEVEL_USER)
|
||||
MACRO_CONFIG_INT(GfxAlphabits, gfx_alphabits, 0, 0, 0, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Alpha bits for framebuffer (fullscreen only)", IConsole::CONSOLELEVEL_USER)
|
||||
MACRO_CONFIG_INT(GfxAlphabits, gfx_alphabits, 0, 0, 0, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Alpha bits for framebuffer (fullscreen only)", IConsole::CONSOLELEVEL_USER)
|
||||
MACRO_CONFIG_INT(GfxColorDepth, gfx_color_depth, 24, 16, 24, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Colors bits for framebuffer (fullscreen only)", IConsole::CONSOLELEVEL_USER)
|
||||
MACRO_CONFIG_INT(GfxClear, gfx_clear, 0, 0, 1, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Clear screen before rendering", IConsole::CONSOLELEVEL_USER)
|
||||
MACRO_CONFIG_INT(GfxVsync, gfx_vsync, 1, 0, 1, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Vertical sync", IConsole::CONSOLELEVEL_USER)
|
||||
|
|
|
@ -51,21 +51,21 @@ int CConsole::ParseStart(CResult *pResult, const char *pString, int Length)
|
|||
int Len = sizeof(pResult->m_aStringStorage);
|
||||
if(Length < Len)
|
||||
Len = Length;
|
||||
|
||||
|
||||
str_copy(pResult->m_aStringStorage, pString, Length);
|
||||
pStr = pResult->m_aStringStorage;
|
||||
|
||||
|
||||
// get command
|
||||
pStr = str_skip_whitespaces(pStr);
|
||||
pResult->m_pCommand = pStr;
|
||||
pStr = str_skip_to_whitespace(pStr);
|
||||
|
||||
|
||||
if(*pStr)
|
||||
{
|
||||
pStr[0] = 0;
|
||||
pStr++;
|
||||
}
|
||||
|
||||
|
||||
pResult->m_pArgsStart = pStr;
|
||||
return 0;
|
||||
}
|
||||
|
@ -78,24 +78,24 @@ int CConsole::ParseArgs(CResult *pResult, const char *pFormat)
|
|||
int Error = 0;
|
||||
|
||||
pResult->ResetVictim();
|
||||
|
||||
|
||||
pStr = pResult->m_pArgsStart;
|
||||
|
||||
while(1)
|
||||
while(1)
|
||||
{
|
||||
// fetch command
|
||||
Command = *pFormat;
|
||||
pFormat++;
|
||||
|
||||
|
||||
if(!Command)
|
||||
break;
|
||||
|
||||
|
||||
if(Command == '?')
|
||||
Optional = 1;
|
||||
else
|
||||
{
|
||||
pStr = str_skip_whitespaces(pStr);
|
||||
|
||||
|
||||
if(!(*pStr)) // error, non optional command needs value
|
||||
{
|
||||
if(!Optional)
|
||||
|
@ -115,14 +115,14 @@ int CConsole::ParseArgs(CResult *pResult, const char *pFormat)
|
|||
}
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
// add token
|
||||
if(*pStr == '"')
|
||||
{
|
||||
char *pDst;
|
||||
pStr++;
|
||||
pResult->AddArgument(pStr);
|
||||
|
||||
|
||||
pDst = pStr; // we might have to process escape data
|
||||
while(1)
|
||||
{
|
||||
|
@ -137,22 +137,22 @@ int CConsole::ParseArgs(CResult *pResult, const char *pFormat)
|
|||
}
|
||||
else if(pStr[0] == 0)
|
||||
return 1; // return error
|
||||
|
||||
|
||||
*pDst = *pStr;
|
||||
pDst++;
|
||||
pStr++;
|
||||
}
|
||||
|
||||
|
||||
// write null termination
|
||||
*pDst = 0;
|
||||
|
||||
|
||||
|
||||
pStr++;
|
||||
}
|
||||
else
|
||||
{
|
||||
char* pVictim = 0;
|
||||
|
||||
|
||||
if (Command != 'v')
|
||||
pResult->AddArgument(pStr);
|
||||
else
|
||||
|
@ -206,14 +206,14 @@ bool CConsole::LineIsValid(const char *pStr)
|
|||
{
|
||||
if(!pStr || *pStr == 0)
|
||||
return false;
|
||||
|
||||
|
||||
do
|
||||
{
|
||||
CResult Result;
|
||||
const char *pEnd = pStr;
|
||||
const char *pNextPart = 0;
|
||||
int InString = 0;
|
||||
|
||||
|
||||
while(*pEnd)
|
||||
{
|
||||
if(*pEnd == '"')
|
||||
|
@ -225,25 +225,25 @@ bool CConsole::LineIsValid(const char *pStr)
|
|||
}
|
||||
else if(!InString)
|
||||
{
|
||||
if(*pEnd == ';') // command separator
|
||||
if(*pEnd == ';') // command separator
|
||||
{
|
||||
pNextPart = pEnd+1;
|
||||
break;
|
||||
}
|
||||
else if(*pEnd == '#') // comment, no need to do anything more
|
||||
else if(*pEnd == '#') // comment, no need to do anything more
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
pEnd++;
|
||||
}
|
||||
|
||||
|
||||
if(ParseStart(&Result, pStr, (pEnd-pStr) + 1) != 0)
|
||||
return false;
|
||||
|
||||
CCommand *pCommand = FindCommand(Result.m_pCommand, m_FlagMask);
|
||||
if(!pCommand || ParseArgs(&Result, pCommand->m_pParams))
|
||||
return false;
|
||||
|
||||
|
||||
pStr = pNextPart;
|
||||
}
|
||||
while(pStr && *pStr);
|
||||
|
@ -257,7 +257,7 @@ void CConsole::ExecuteLineStroked(int Stroke, const char *pStr, int ClientID, in
|
|||
}
|
||||
|
||||
void CConsole::ExecuteLineStroked(int Stroke, const char *pStr, int ClientID, int Level, IConsole::FPrintCallback pfnPrintCallback, void *pPrintCallbackUserData)
|
||||
{
|
||||
{
|
||||
while(pStr && *pStr)
|
||||
{
|
||||
CResult Result;
|
||||
|
@ -269,7 +269,7 @@ void CConsole::ExecuteLineStroked(int Stroke, const char *pStr, int ClientID, in
|
|||
Result.SetPrintCallback(pfnPrintCallback, pPrintCallbackUserData);
|
||||
else
|
||||
Result.SetPrintCallback(m_pfnPrintCallback, m_pPrintCallbackUserData);
|
||||
|
||||
|
||||
while(*pEnd)
|
||||
{
|
||||
if(*pEnd == '"')
|
||||
|
@ -281,18 +281,18 @@ void CConsole::ExecuteLineStroked(int Stroke, const char *pStr, int ClientID, in
|
|||
}
|
||||
else if(!InString)
|
||||
{
|
||||
if(*pEnd == ';') // command separator
|
||||
if(*pEnd == ';') // command separator
|
||||
{
|
||||
pNextPart = pEnd+1;
|
||||
break;
|
||||
}
|
||||
else if(*pEnd == '#') // comment, no need to do anything more
|
||||
else if(*pEnd == '#') // comment, no need to do anything more
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
pEnd++;
|
||||
}
|
||||
|
||||
|
||||
if(ParseStart(&Result, pStr, (pEnd-pStr) + 1) != 0)
|
||||
return;
|
||||
|
||||
|
@ -307,7 +307,7 @@ void CConsole::ExecuteLineStroked(int Stroke, const char *pStr, int ClientID, in
|
|||
Result.AddArgument(m_paStrokeStr[Stroke]);
|
||||
IsStrokeCommand = 1;
|
||||
}
|
||||
|
||||
|
||||
if(Stroke || IsStrokeCommand)
|
||||
{
|
||||
if(ParseArgs(&Result, pCommand->m_pParams))
|
||||
|
@ -395,7 +395,7 @@ void CConsole::ExecuteLineStroked(int Stroke, const char *pStr, int ClientID, in
|
|||
str_format(aBuf, sizeof(aBuf), "No such command: %s.", Result.m_pCommand);
|
||||
Result.Print(OUTPUT_LEVEL_STANDARD, "Console", aBuf);
|
||||
}
|
||||
|
||||
|
||||
pStr = pNextPart;
|
||||
}
|
||||
}
|
||||
|
@ -410,7 +410,7 @@ void CConsole::PossibleCommands(const char *pStr, int FlagMask, FPossibleCallbac
|
|||
if(str_find_nocase(pCommand->m_pName, pStr))
|
||||
pfnCallback(pCommand->m_pName, pUser);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CConsole::CCommand *CConsole::FindCommand(const char *pName, int FlagMask)
|
||||
|
@ -423,8 +423,8 @@ CConsole::CCommand *CConsole::FindCommand(const char *pName, int FlagMask)
|
|||
if(str_comp_nocase(pCommand->m_pName, pName) == 0)
|
||||
return pCommand;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return 0x0;
|
||||
}
|
||||
|
||||
|
@ -455,7 +455,7 @@ void CConsole::ExecuteFile(const char *pFilename, int ClientID, int Level, ICons
|
|||
m_pStorage = Kernel()->RequestInterface<IStorage>();
|
||||
if(!m_pStorage)
|
||||
return;
|
||||
|
||||
|
||||
// push this one to the stack
|
||||
CExecFile ThisFile;
|
||||
CExecFile *pPrev = m_pFirstExec;
|
||||
|
@ -465,7 +465,7 @@ void CConsole::ExecuteFile(const char *pFilename, int ClientID, int Level, ICons
|
|||
|
||||
// exec the file
|
||||
IOHANDLE File = m_pStorage->OpenFile(pFilename, IOFLAG_READ, IStorage::TYPE_ALL);
|
||||
|
||||
|
||||
CResult Result;
|
||||
Result.SetPrintCallback(pfnPrintCallback, pPrintCallbackUserData);
|
||||
|
||||
|
@ -474,7 +474,7 @@ void CConsole::ExecuteFile(const char *pFilename, int ClientID, int Level, ICons
|
|||
{
|
||||
char *pLine;
|
||||
CLineReader lr;
|
||||
|
||||
|
||||
str_format(aBuf, sizeof(aBuf), "executing '%s'", pFilename);
|
||||
Result.Print(IConsole::OUTPUT_LEVEL_STANDARD, "console", aBuf);
|
||||
lr.Init(File);
|
||||
|
@ -489,7 +489,7 @@ void CConsole::ExecuteFile(const char *pFilename, int ClientID, int Level, ICons
|
|||
str_format(aBuf, sizeof(aBuf), "failed to open '%s'", pFilename);
|
||||
Result.Print(IConsole::OUTPUT_LEVEL_STANDARD, "console", aBuf);
|
||||
}
|
||||
|
||||
|
||||
m_pFirstExec = pPrev;
|
||||
}
|
||||
|
||||
|
@ -527,7 +527,7 @@ static void IntVariableCommand(IConsole::IResult *pResult, void *pUserData, int
|
|||
if(pResult->NumArguments())
|
||||
{
|
||||
int Val = pResult->GetInteger(0);
|
||||
|
||||
|
||||
// do clamping
|
||||
if(pData->m_Min != pData->m_Max)
|
||||
{
|
||||
|
@ -607,30 +607,30 @@ CConsole::CConsole(int FlagMask)
|
|||
m_pfnCompareClientsCallback = 0;
|
||||
m_pClientOnlineUserdata = 0;
|
||||
m_pCompareClientsUserdata = 0;
|
||||
|
||||
|
||||
m_pStorage = 0;
|
||||
|
||||
|
||||
// register some basic commands
|
||||
Register("echo", "r", CFGFLAG_SERVER|CFGFLAG_CLIENT, Con_Echo, this, "Echo the text", IConsole::CONSOLELEVEL_ADMIN);
|
||||
Register("exec", "r", CFGFLAG_SERVER|CFGFLAG_CLIENT, Con_Exec, this, "Execute the specified file", IConsole::CONSOLELEVEL_ADMIN);
|
||||
|
||||
|
||||
// TODO: this should disappear
|
||||
#define MACRO_CONFIG_INT(Name,ScriptName,Def,Min,Max,Flags,Desc,Level) \
|
||||
{ \
|
||||
static CIntVariableData Data = { this, #ScriptName, &g_Config.m_##Name, Min, Max }; \
|
||||
Register(#ScriptName, "?i", Flags, IntVariableCommand, &Data, Desc, Level); \
|
||||
}
|
||||
|
||||
|
||||
#define MACRO_CONFIG_STR(Name,ScriptName,Len,Def,Flags,Desc,Level) \
|
||||
{ \
|
||||
static CStrVariableData Data = { this, #ScriptName, g_Config.m_##Name, Len }; \
|
||||
Register(#ScriptName, "?r", Flags, StrVariableCommand, &Data, Desc, Level); \
|
||||
}
|
||||
|
||||
#include "config_variables.h"
|
||||
#include "config_variables.h"
|
||||
|
||||
#undef MACRO_CONFIG_INT
|
||||
#undef MACRO_CONFIG_STR
|
||||
#undef MACRO_CONFIG_INT
|
||||
#undef MACRO_CONFIG_STR
|
||||
|
||||
m_Cheated = false;
|
||||
}
|
||||
|
@ -659,7 +659,7 @@ void CConsole::ParseArguments(int NumArgs, const char **ppArguments)
|
|||
}
|
||||
}
|
||||
|
||||
void CConsole::Register(const char *pName, const char *pParams,
|
||||
void CConsole::Register(const char *pName, const char *pParams,
|
||||
int Flags, FCommandCallback pfnFunc, void *pUser, const char *pHelp, const int Level)
|
||||
{
|
||||
CCommand *pCommand = (CCommand *)mem_alloc(sizeof(CCommand), sizeof(void*));
|
||||
|
@ -671,7 +671,6 @@ void CConsole::Register(const char *pName, const char *pParams,
|
|||
pCommand->m_Flags = Flags;
|
||||
pCommand->m_Level = Level;
|
||||
|
||||
|
||||
pCommand->m_pNext = m_pFirstCommand;
|
||||
m_pFirstCommand = pCommand;
|
||||
m_aCommandCount[pCommand->m_Level]++;
|
||||
|
@ -686,13 +685,13 @@ void CConsole::Con_Chain(IResult *pResult, void *pUserData, int ClientID)
|
|||
void CConsole::Chain(const char *pName, FChainCommandCallback pfnChainFunc, void *pUser)
|
||||
{
|
||||
CCommand *pCommand = FindCommand(pName, m_FlagMask);
|
||||
|
||||
|
||||
if(!pCommand)
|
||||
{
|
||||
dbg_msg("console", "failed to chain '%s'", pName);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
CChain *pChainInfo = (CChain *)mem_alloc(sizeof(CChain), sizeof(void*));
|
||||
|
||||
// store info
|
||||
|
@ -700,7 +699,7 @@ void CConsole::Chain(const char *pName, FChainCommandCallback pfnChainFunc, void
|
|||
pChainInfo->m_pUserData = pUser;
|
||||
pChainInfo->m_pfnCallback = pCommand->m_pfnCallback;
|
||||
pChainInfo->m_pCallbackUserData = pCommand->m_pUserData;
|
||||
|
||||
|
||||
// chain
|
||||
pCommand->m_pfnCallback = Con_Chain;
|
||||
pCommand->m_pUserData = pChainInfo;
|
||||
|
|
|
@ -18,7 +18,7 @@ class CConsole : public IConsole
|
|||
FCommandCallback m_pfnCallback;
|
||||
void *m_pUserData;
|
||||
};
|
||||
|
||||
|
||||
|
||||
class CChain
|
||||
{
|
||||
|
@ -27,8 +27,8 @@ class CConsole : public IConsole
|
|||
FCommandCallback m_pfnCallback;
|
||||
void *m_pCallbackUserData;
|
||||
void *m_pUserData;
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
int m_FlagMask;
|
||||
bool m_StoreCommands;
|
||||
const char *m_paStrokeStr[2];
|
||||
|
@ -40,7 +40,7 @@ class CConsole : public IConsole
|
|||
const char *m_pFilename;
|
||||
struct CExecFile *m_pPrev;
|
||||
};
|
||||
|
||||
|
||||
CExecFile *m_pFirstExec;
|
||||
class IStorage *m_pStorage;
|
||||
|
||||
|
@ -50,22 +50,22 @@ class CConsole : public IConsole
|
|||
|
||||
//void ExecuteFileRecurse(const char *pFilename);
|
||||
//void ExecuteLineStroked(int Stroke, const char *pStr);
|
||||
|
||||
|
||||
FPrintCallback m_pfnPrintCallback;
|
||||
void *m_pPrintCallbackUserData;
|
||||
|
||||
enum
|
||||
{
|
||||
CONSOLE_MAX_STR_LENGTH = 1024,
|
||||
CONSOLE_MAX_STR_LENGTH = 1024,
|
||||
MAX_PARTS = (CONSOLE_MAX_STR_LENGTH+1)/2
|
||||
};
|
||||
|
||||
|
||||
class CResult : public IResult
|
||||
{
|
||||
public:
|
||||
char m_aStringStorage[CONSOLE_MAX_STR_LENGTH+1];
|
||||
char *m_pArgsStart;
|
||||
|
||||
|
||||
const char *m_pCommand;
|
||||
const char *m_apArgs[MAX_PARTS];
|
||||
|
||||
|
@ -91,7 +91,7 @@ class CConsole : public IConsole
|
|||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
void AddArgument(const char *pArg)
|
||||
{
|
||||
m_apArgs[m_NumArgs++] = pArg;
|
||||
|
@ -122,7 +122,7 @@ class CConsole : public IConsole
|
|||
virtual void Print(int Level, const char *pFrom, const char *pStr);
|
||||
virtual void SetPrintCallback(IConsole::FPrintCallback pfnPrintCallback, void *pPrintCallbackUserData) { m_pfnPrintCallback = pfnPrintCallback; m_pPrintCallbackUserData = pPrintCallbackUserData; }
|
||||
};
|
||||
|
||||
|
||||
int ParseStart(CResult *pResult, const char *pString, int Length);
|
||||
int ParseArgs(CResult *pResult, const char *pFormat);
|
||||
|
||||
|
@ -169,7 +169,7 @@ public:
|
|||
virtual void Register(const char *pName, const char *pParams, int Flags, FCommandCallback pfnFunc, void *pUser, const char *pHelp, const int Level);
|
||||
virtual void Chain(const char *pName, FChainCommandCallback pfnChainFunc, void *pUser);
|
||||
virtual void StoreCommands(bool Store, int ClientID);
|
||||
|
||||
|
||||
virtual bool LineIsValid(const char *pStr);
|
||||
//virtual void ExecuteLine(const char *pStr);
|
||||
//virtual void ExecuteFile(const char *pFilename);
|
||||
|
|
|
@ -75,9 +75,9 @@ bool CDataFileReader::Open(class IStorage *pStorage, const char *pFilename, int
|
|||
{
|
||||
dbg_msg("datafile", "could not open '%s'", pFilename);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
// take the CRC of the file and store it
|
||||
unsigned Crc = 0;
|
||||
{
|
||||
|
@ -85,9 +85,9 @@ bool CDataFileReader::Open(class IStorage *pStorage, const char *pFilename, int
|
|||
{
|
||||
BUFFER_SIZE = 64*1024
|
||||
};
|
||||
|
||||
|
||||
unsigned char aBuffer[BUFFER_SIZE];
|
||||
|
||||
|
||||
while(1)
|
||||
{
|
||||
unsigned Bytes = io_read(File, aBuffer, BUFFER_SIZE);
|
||||
|
@ -95,11 +95,11 @@ bool CDataFileReader::Open(class IStorage *pStorage, const char *pFilename, int
|
|||
break;
|
||||
Crc = crc32(Crc, aBuffer, Bytes); // ignore_convention
|
||||
}
|
||||
|
||||
|
||||
io_seek(File, 0, IOSEEK_START);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// TODO: change this header
|
||||
CDatafileHeader Header;
|
||||
io_read(File, &Header, sizeof(Header));
|
||||
|
@ -113,14 +113,14 @@ bool CDataFileReader::Open(class IStorage *pStorage, const char *pFilename, int
|
|||
}
|
||||
|
||||
#if defined(CONF_ARCH_ENDIAN_BIG)
|
||||
swap_endian(&Header, sizeof(int), sizeof(Header)/sizeof(int));
|
||||
swap_endian(&Header, sizeof(int), sizeof(Header)/sizeof(int));
|
||||
#endif
|
||||
if(Header.m_Version != 3 && Header.m_Version != 4)
|
||||
{
|
||||
dbg_msg("datafile", "wrong version. version=%x", Header.m_Version);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// read in the rest except the data
|
||||
unsigned Size = 0;
|
||||
Size += Header.m_NumItemTypes*sizeof(CDatafileItemType);
|
||||
|
@ -128,7 +128,7 @@ bool CDataFileReader::Open(class IStorage *pStorage, const char *pFilename, int
|
|||
if(Header.m_Version == 4)
|
||||
Size += Header.m_NumRawData*sizeof(int); // v4 has uncompressed data sizes aswell
|
||||
Size += Header.m_ItemSize;
|
||||
|
||||
|
||||
unsigned AllocSize = Size;
|
||||
AllocSize += sizeof(CDatafile); // add space for info structure
|
||||
AllocSize += Header.m_NumRawData*sizeof(void*); // add space for data pointers
|
||||
|
@ -140,10 +140,10 @@ bool CDataFileReader::Open(class IStorage *pStorage, const char *pFilename, int
|
|||
pTmpDataFile->m_pData = (char *)(pTmpDataFile+1)+Header.m_NumRawData*sizeof(char *);
|
||||
pTmpDataFile->m_File = File;
|
||||
pTmpDataFile->m_Crc = Crc;
|
||||
|
||||
|
||||
// clear the data pointers
|
||||
mem_zero(pTmpDataFile->m_ppDataPtrs, Header.m_NumRawData*sizeof(void*));
|
||||
|
||||
|
||||
// read types, offsets, sizes and item data
|
||||
unsigned ReadSize = io_read(File, pTmpDataFile->m_pData, Size);
|
||||
if(ReadSize != Size)
|
||||
|
@ -169,12 +169,12 @@ bool CDataFileReader::Open(class IStorage *pStorage, const char *pFilename, int
|
|||
dbg_msg("datafile", "swaplen=%d", Header.m_Swaplen);
|
||||
dbg_msg("datafile", "item_size=%d", m_pDataFile->m_Header.m_ItemSize);
|
||||
}
|
||||
|
||||
|
||||
m_pDataFile->m_Info.m_pItemTypes = (CDatafileItemType *)m_pDataFile->m_pData;
|
||||
m_pDataFile->m_Info.m_pItemOffsets = (int *)&m_pDataFile->m_Info.m_pItemTypes[m_pDataFile->m_Header.m_NumItemTypes];
|
||||
m_pDataFile->m_Info.m_pDataOffsets = (int *)&m_pDataFile->m_Info.m_pItemOffsets[m_pDataFile->m_Header.m_NumItems];
|
||||
m_pDataFile->m_Info.m_pDataSizes = (int *)&m_pDataFile->m_Info.m_pDataOffsets[m_pDataFile->m_Header.m_NumRawData];
|
||||
|
||||
|
||||
if(Header.m_Version == 4)
|
||||
m_pDataFile->m_Info.m_pItemStart = (char *)&m_pDataFile->m_Info.m_pDataSizes[m_pDataFile->m_Header.m_NumRawData];
|
||||
else
|
||||
|
@ -191,7 +191,7 @@ bool CDataFileReader::Open(class IStorage *pStorage, const char *pFilename, int
|
|||
void *p = datafile_get_data(df, i);
|
||||
dbg_msg("datafile", "%d %d", (int)((char*)p - (char*)(&m_pDataFile->data)), size);
|
||||
}
|
||||
|
||||
|
||||
for(int i = 0; i < datafile_num_items(df); i++)
|
||||
{
|
||||
int type, id;
|
||||
|
@ -218,7 +218,7 @@ bool CDataFileReader::Open(class IStorage *pStorage, const char *pFilename, int
|
|||
}
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -227,7 +227,7 @@ bool CDataFileReader::GetCrcSize(class IStorage *pStorage, const char *pFilename
|
|||
IOHANDLE File = pStorage->OpenFile(pFilename, IOFLAG_READ, StorageType);
|
||||
if(!File)
|
||||
return false;
|
||||
|
||||
|
||||
// get crc and size
|
||||
unsigned Crc = 0;
|
||||
unsigned Size = 0;
|
||||
|
@ -240,7 +240,7 @@ bool CDataFileReader::GetCrcSize(class IStorage *pStorage, const char *pFilename
|
|||
Crc = crc32(Crc, aBuffer, Bytes); // ignore_convention
|
||||
Size += Bytes;
|
||||
}
|
||||
|
||||
|
||||
io_close(File);
|
||||
|
||||
*pCrc = Crc;
|
||||
|
@ -258,23 +258,23 @@ int CDataFileReader::NumData()
|
|||
int CDataFileReader::GetDataSize(int Index)
|
||||
{
|
||||
if(!m_pDataFile) { return 0; }
|
||||
|
||||
|
||||
if(Index == m_pDataFile->m_Header.m_NumRawData-1)
|
||||
return m_pDataFile->m_Header.m_DataSize-m_pDataFile->m_Info.m_pDataOffsets[Index];
|
||||
return m_pDataFile->m_Info.m_pDataOffsets[Index+1]-m_pDataFile->m_Info.m_pDataOffsets[Index];
|
||||
return m_pDataFile->m_Info.m_pDataOffsets[Index+1]-m_pDataFile->m_Info.m_pDataOffsets[Index];
|
||||
}
|
||||
|
||||
void *CDataFileReader::GetDataImpl(int Index, int Swap)
|
||||
{
|
||||
if(!m_pDataFile) { return 0; }
|
||||
|
||||
|
||||
// load it if needed
|
||||
if(!m_pDataFile->m_ppDataPtrs[Index])
|
||||
{
|
||||
// fetch the data size
|
||||
int DataSize = GetDataSize(Index);
|
||||
int SwapSize = DataSize;
|
||||
|
||||
|
||||
if(m_pDataFile->m_Header.m_Version == 4)
|
||||
{
|
||||
// v4 has compressed data
|
||||
|
@ -284,7 +284,7 @@ void *CDataFileReader::GetDataImpl(int Index, int Swap)
|
|||
|
||||
dbg_msg("datafile", "loading data index=%d size=%d uncompressed=%d", Index, DataSize, UncompressedSize);
|
||||
m_pDataFile->m_ppDataPtrs[Index] = (char *)mem_alloc(UncompressedSize, 1);
|
||||
|
||||
|
||||
// read the compressed data
|
||||
io_seek(m_pDataFile->m_File, m_pDataFile->m_DataStartOffset+m_pDataFile->m_Info.m_pDataOffsets[Index], IOSEEK_START);
|
||||
io_read(m_pDataFile->m_File, pTemp, DataSize);
|
||||
|
@ -311,7 +311,7 @@ void *CDataFileReader::GetDataImpl(int Index, int Swap)
|
|||
swap_endian(m_pDataFile->m_ppDataPtrs[Index], sizeof(int), SwapSize/sizeof(int));
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
return m_pDataFile->m_ppDataPtrs[Index];
|
||||
}
|
||||
|
||||
|
@ -329,7 +329,7 @@ void CDataFileReader::UnloadData(int Index)
|
|||
{
|
||||
if(Index < 0)
|
||||
return;
|
||||
|
||||
|
||||
//
|
||||
mem_free(m_pDataFile->m_ppDataPtrs[Index]);
|
||||
m_pDataFile->m_ppDataPtrs[Index] = 0x0;
|
||||
|
@ -340,13 +340,13 @@ int CDataFileReader::GetItemSize(int Index)
|
|||
if(!m_pDataFile) { return 0; }
|
||||
if(Index == m_pDataFile->m_Header.m_NumItems-1)
|
||||
return m_pDataFile->m_Header.m_ItemSize-m_pDataFile->m_Info.m_pItemOffsets[Index];
|
||||
return m_pDataFile->m_Info.m_pItemOffsets[Index+1]-m_pDataFile->m_Info.m_pItemOffsets[Index];
|
||||
return m_pDataFile->m_Info.m_pItemOffsets[Index+1]-m_pDataFile->m_Info.m_pItemOffsets[Index];
|
||||
}
|
||||
|
||||
void *CDataFileReader::GetItem(int Index, int *pType, int *pID)
|
||||
{
|
||||
if(!m_pDataFile) { if(pType) *pType = 0; if(pID) *pID = 0; return 0; }
|
||||
|
||||
|
||||
CDatafileItem *i = (CDatafileItem *)(m_pDataFile->m_Info.m_pItemStart+m_pDataFile->m_Info.m_pItemOffsets[Index]);
|
||||
if(pType)
|
||||
*pType = (i->m_TypeAndID>>16)&0xffff; // remove sign extention
|
||||
|
@ -362,7 +362,7 @@ void CDataFileReader::GetType(int Type, int *pStart, int *pNum)
|
|||
|
||||
if(!m_pDataFile)
|
||||
return;
|
||||
|
||||
|
||||
for(int i = 0; i < m_pDataFile->m_Header.m_NumItemTypes; i++)
|
||||
{
|
||||
if(m_pDataFile->m_Info.m_pItemTypes[i].m_Type == Type)
|
||||
|
@ -377,7 +377,7 @@ void CDataFileReader::GetType(int Type, int *pStart, int *pNum)
|
|||
void *CDataFileReader::FindItem(int Type, int ID)
|
||||
{
|
||||
if(!m_pDataFile) return 0;
|
||||
|
||||
|
||||
int Start, Num;
|
||||
GetType(Type, &Start, &Num);
|
||||
for(int i = 0; i < Num; i++)
|
||||
|
@ -400,12 +400,12 @@ bool CDataFileReader::Close()
|
|||
{
|
||||
if(!m_pDataFile)
|
||||
return true;
|
||||
|
||||
|
||||
// free the data that is loaded
|
||||
int i;
|
||||
for(i = 0; i < m_pDataFile->m_Header.m_NumRawData; i++)
|
||||
mem_free(m_pDataFile->m_ppDataPtrs[i]);
|
||||
|
||||
|
||||
io_close(m_pDataFile->m_File);
|
||||
mem_free(m_pDataFile);
|
||||
m_pDataFile = 0;
|
||||
|
@ -424,7 +424,7 @@ bool CDataFileWriter::Open(class IStorage *pStorage, const char *pFilename)
|
|||
m_File = pStorage->OpenFile(pFilename, IOFLAG_WRITE, IStorage::TYPE_SAVE);
|
||||
if(!m_File)
|
||||
return false;
|
||||
|
||||
|
||||
m_NumItems = 0;
|
||||
m_NumDatas = 0;
|
||||
m_NumItemTypes = 0;
|
||||
|
@ -435,7 +435,7 @@ bool CDataFileWriter::Open(class IStorage *pStorage, const char *pFilename)
|
|||
m_aItemTypes[i].m_First = -1;
|
||||
m_aItemTypes[i].m_Last = -1;
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -450,7 +450,7 @@ int CDataFileWriter::AddItem(int Type, int ID, int Size, void *pData)
|
|||
m_aItems[m_NumItems].m_Type = Type;
|
||||
m_aItems[m_NumItems].m_ID = ID;
|
||||
m_aItems[m_NumItems].m_Size = Size;
|
||||
|
||||
|
||||
// copy data
|
||||
m_aItems[m_NumItems].m_pData = mem_alloc(Size, 1);
|
||||
mem_copy(m_aItems[m_NumItems].m_pData, pData, Size);
|
||||
|
@ -461,16 +461,16 @@ int CDataFileWriter::AddItem(int Type, int ID, int Size, void *pData)
|
|||
// link
|
||||
m_aItems[m_NumItems].m_Prev = m_aItemTypes[Type].m_Last;
|
||||
m_aItems[m_NumItems].m_Next = -1;
|
||||
|
||||
|
||||
if(m_aItemTypes[Type].m_Last != -1)
|
||||
m_aItems[m_aItemTypes[Type].m_Last].m_Next = m_NumItems;
|
||||
m_aItemTypes[Type].m_Last = m_NumItems;
|
||||
|
||||
|
||||
if(m_aItemTypes[Type].m_First == -1)
|
||||
m_aItemTypes[Type].m_First = m_NumItems;
|
||||
|
||||
|
||||
m_aItemTypes[Type].m_Num++;
|
||||
|
||||
|
||||
m_NumItems++;
|
||||
return m_NumItems-1;
|
||||
}
|
||||
|
@ -491,7 +491,7 @@ int CDataFileWriter::AddData(int Size, void *pData)
|
|||
dbg_msg("datafile", "compression error %d", Result);
|
||||
dbg_assert(0, "zlib error");
|
||||
}
|
||||
|
||||
|
||||
pInfo->m_UncompressedSize = Size;
|
||||
pInfo->m_CompressedSize = (int)s;
|
||||
pInfo->m_pCompressedData = mem_alloc(pInfo->m_CompressedSize, 1);
|
||||
|
@ -539,23 +539,23 @@ int CDataFileWriter::Finish()
|
|||
dbg_msg("datafile", "item=%d size=%d (%d)", i, m_aItems[i].m_Size, m_aItems[i].m_Size+sizeof(CDatafileItem));
|
||||
ItemSize += m_aItems[i].m_Size + sizeof(CDatafileItem);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
for(int i = 0; i < m_NumDatas; i++)
|
||||
DataSize += m_aDatas[i].m_CompressedSize;
|
||||
|
||||
|
||||
// calculate the complete size
|
||||
TypesSize = m_NumItemTypes*sizeof(CDatafileItemType);
|
||||
HeaderSize = sizeof(CDatafileHeader);
|
||||
OffsetSize = (m_NumItems + m_NumDatas + m_NumDatas) * sizeof(int); // ItemOffsets, DataOffsets, DataUncompressedSizes
|
||||
FileSize = HeaderSize + TypesSize + OffsetSize + ItemSize + DataSize;
|
||||
SwapSize = FileSize - DataSize;
|
||||
|
||||
|
||||
(void)SwapSize;
|
||||
|
||||
|
||||
if(DEBUG)
|
||||
dbg_msg("datafile", "num_m_aItemTypes=%d TypesSize=%d m_aItemsize=%d DataSize=%d", m_NumItemTypes, TypesSize, ItemSize, DataSize);
|
||||
|
||||
|
||||
// construct Header
|
||||
{
|
||||
Header.m_aID[0] = 'D';
|
||||
|
@ -570,7 +570,7 @@ int CDataFileWriter::Finish()
|
|||
Header.m_NumRawData = m_NumDatas;
|
||||
Header.m_ItemSize = ItemSize;
|
||||
Header.m_DataSize = DataSize;
|
||||
|
||||
|
||||
// write Header
|
||||
if(DEBUG)
|
||||
dbg_msg("datafile", "HeaderSize=%d", sizeof(Header));
|
||||
|
@ -579,7 +579,7 @@ int CDataFileWriter::Finish()
|
|||
#endif
|
||||
io_write(m_File, &Header, sizeof(Header));
|
||||
}
|
||||
|
||||
|
||||
// write types
|
||||
for(int i = 0, Count = 0; i < 0xffff; i++)
|
||||
{
|
||||
|
@ -599,7 +599,7 @@ int CDataFileWriter::Finish()
|
|||
Count += m_aItemTypes[i].m_Num;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// write item offsets
|
||||
for(int i = 0, Offset = 0; i < 0xffff; i++)
|
||||
{
|
||||
|
@ -617,13 +617,13 @@ int CDataFileWriter::Finish()
|
|||
#endif
|
||||
io_write(m_File, &Temp, sizeof(Temp));
|
||||
Offset += m_aItems[k].m_Size + sizeof(CDatafileItem);
|
||||
|
||||
|
||||
// next
|
||||
k = m_aItems[k].m_Next;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// write data offsets
|
||||
for(int i = 0, Offset = 0; i < m_NumDatas; i++)
|
||||
{
|
||||
|
@ -648,7 +648,7 @@ int CDataFileWriter::Finish()
|
|||
#endif
|
||||
io_write(m_File, &UncompressedSize, sizeof(UncompressedSize));
|
||||
}
|
||||
|
||||
|
||||
// write m_aItems
|
||||
for(int i = 0; i < 0xffff; i++)
|
||||
{
|
||||
|
@ -663,20 +663,20 @@ int CDataFileWriter::Finish()
|
|||
Item.m_Size = m_aItems[k].m_Size;
|
||||
if(DEBUG)
|
||||
dbg_msg("datafile", "writing item type=%x idx=%d id=%d size=%d", i, k, m_aItems[k].m_ID, m_aItems[k].m_Size);
|
||||
|
||||
|
||||
#if defined(CONF_ARCH_ENDIAN_BIG)
|
||||
swap_endian(&Item, sizeof(int), sizeof(Item)/sizeof(int));
|
||||
swap_endian(m_aItems[k].m_pData, sizeof(int), m_aItems[k].m_Size/sizeof(int));
|
||||
#endif
|
||||
io_write(m_File, &Item, sizeof(Item));
|
||||
io_write(m_File, m_aItems[k].m_pData, m_aItems[k].m_Size);
|
||||
|
||||
|
||||
// next
|
||||
k = m_aItems[k].m_Next;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// write data
|
||||
for(int i = 0; i < m_NumDatas; i++)
|
||||
{
|
||||
|
@ -690,10 +690,10 @@ int CDataFileWriter::Finish()
|
|||
mem_free(m_aItems[i].m_pData);
|
||||
for(int i = 0; i < m_NumDatas; ++i)
|
||||
mem_free(m_aDatas[i].m_pCompressedData);
|
||||
|
||||
|
||||
io_close(m_File);
|
||||
m_File = 0;
|
||||
|
||||
|
||||
if(DEBUG)
|
||||
dbg_msg("datafile", "done");
|
||||
return 0;
|
||||
|
|
|
@ -11,14 +11,14 @@ class CDataFileReader
|
|||
public:
|
||||
CDataFileReader() : m_pDataFile(0) {}
|
||||
~CDataFileReader() { Close(); }
|
||||
|
||||
|
||||
bool IsOpen() const { return m_pDataFile != 0; }
|
||||
|
||||
|
||||
bool Open(class IStorage *pStorage, const char *pFilename, int StorageType);
|
||||
bool Close();
|
||||
|
||||
static bool GetCrcSize(class IStorage *pStorage, const char *pFilename, int StorageType, unsigned *pCrc, unsigned *pSize);
|
||||
|
||||
|
||||
void *GetData(int Index);
|
||||
void *GetDataSwapped(int Index); // makes sure that the data is 32bit LE ints when saved
|
||||
int GetDataSize(int Index);
|
||||
|
@ -30,7 +30,7 @@ public:
|
|||
int NumItems();
|
||||
int NumData();
|
||||
void Unload();
|
||||
|
||||
|
||||
unsigned Crc();
|
||||
};
|
||||
|
||||
|
@ -60,15 +60,15 @@ class CDataFileWriter
|
|||
int m_First;
|
||||
int m_Last;
|
||||
};
|
||||
|
||||
|
||||
IOHANDLE m_File;
|
||||
int m_NumItems;
|
||||
int m_NumDatas;
|
||||
int m_NumItemTypes;
|
||||
CItemTypeInfo m_aItemTypes[0xffff];
|
||||
CItemInfo m_aItems[1024];
|
||||
CDataInfo m_aDatas[1024];
|
||||
|
||||
CDataInfo m_aDatas[1024];
|
||||
|
||||
public:
|
||||
CDataFileWriter() : m_File(0) {}
|
||||
bool Open(class IStorage *pStorage, const char *Filename);
|
||||
|
|
|
@ -47,7 +47,7 @@ int CDemoRecorder::Start(class IStorage *pStorage, class IConsole *pConsole, con
|
|||
char aBuf[512];
|
||||
str_format(aMapFilename, sizeof(aMapFilename), "%s.map", pMap);
|
||||
if(pStorage->FindFile(aMapFilename, "maps", IStorage::TYPE_ALL, aBuf, sizeof(aBuf)))
|
||||
MapFile = pStorage->OpenFile(aBuf, IOFLAG_READ, IStorage::TYPE_ALL);
|
||||
MapFile = pStorage->OpenFile(aBuf, IOFLAG_READ, IStorage::TYPE_ALL);
|
||||
}
|
||||
if(!MapFile)
|
||||
{
|
||||
|
@ -67,7 +67,7 @@ int CDemoRecorder::Start(class IStorage *pStorage, class IConsole *pConsole, con
|
|||
m_pConsole->Print(IConsole::OUTPUT_LEVEL_STANDARD, "demo_recorder", aBuf);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
// write header
|
||||
mem_zero(&Header, sizeof(Header));
|
||||
mem_copy(Header.m_aMarker, gs_aHeaderMarker, sizeof(Header.m_aMarker));
|
||||
|
@ -87,7 +87,7 @@ int CDemoRecorder::Start(class IStorage *pStorage, class IConsole *pConsole, con
|
|||
// Header.m_Length - add this on stop
|
||||
str_timestamp(Header.m_aTimestamp, sizeof(Header.m_aTimestamp));
|
||||
io_write(DemoFile, &Header, sizeof(Header));
|
||||
|
||||
|
||||
// write map data
|
||||
while(1)
|
||||
{
|
||||
|
@ -98,11 +98,11 @@ int CDemoRecorder::Start(class IStorage *pStorage, class IConsole *pConsole, con
|
|||
io_write(DemoFile, &aChunk, Bytes);
|
||||
}
|
||||
io_close(MapFile);
|
||||
|
||||
|
||||
m_LastKeyFrame = -1;
|
||||
m_LastTickMarker = -1;
|
||||
m_FirstTick = -1;
|
||||
|
||||
|
||||
char aBuf[256];
|
||||
str_format(aBuf, sizeof(aBuf), "Recording to '%s'", pFilename);
|
||||
m_pConsole->Print(IConsole::OUTPUT_LEVEL_STANDARD, "demo_recorder", aBuf);
|
||||
|
@ -113,25 +113,25 @@ int CDemoRecorder::Start(class IStorage *pStorage, class IConsole *pConsole, con
|
|||
|
||||
/*
|
||||
Tickmarker
|
||||
7 = Always set
|
||||
6 = Keyframe flag
|
||||
0-5 = Delta tick
|
||||
|
||||
7 = Always set
|
||||
6 = Keyframe flag
|
||||
0-5 = Delta tick
|
||||
|
||||
Normal
|
||||
7 = Not set
|
||||
5-6 = Type
|
||||
0-4 = Size
|
||||
7 = Not set
|
||||
5-6 = Type
|
||||
0-4 = Size
|
||||
*/
|
||||
|
||||
enum
|
||||
{
|
||||
CHUNKTYPEFLAG_TICKMARKER = 0x80,
|
||||
CHUNKTICKFLAG_KEYFRAME = 0x40, // only when tickmarker is set
|
||||
|
||||
|
||||
CHUNKMASK_TICK = 0x3f,
|
||||
CHUNKMASK_TYPE = 0x60,
|
||||
CHUNKMASK_SIZE = 0x1f,
|
||||
|
||||
|
||||
CHUNKTYPE_SNAPSHOT = 1,
|
||||
CHUNKTYPE_MESSAGE = 2,
|
||||
CHUNKTYPE_DELTA = 3,
|
||||
|
@ -152,7 +152,7 @@ void CDemoRecorder::WriteTickMarker(int Tick, int Keyframe)
|
|||
|
||||
if(Keyframe)
|
||||
aChunk[0] |= CHUNKTICKFLAG_KEYFRAME;
|
||||
|
||||
|
||||
io_write(m_File, aChunk, sizeof(aChunk));
|
||||
}
|
||||
else
|
||||
|
@ -160,7 +160,7 @@ void CDemoRecorder::WriteTickMarker(int Tick, int Keyframe)
|
|||
unsigned char aChunk[1];
|
||||
aChunk[0] = CHUNKTYPEFLAG_TICKMARKER | (Tick-m_LastTickMarker);
|
||||
io_write(m_File, aChunk, sizeof(aChunk));
|
||||
}
|
||||
}
|
||||
|
||||
m_LastTickMarker = Tick;
|
||||
if(m_FirstTick < 0)
|
||||
|
@ -172,7 +172,7 @@ void CDemoRecorder::Write(int Type, const void *pData, int Size)
|
|||
char aBuffer[64*1024];
|
||||
char aBuffer2[64*1024];
|
||||
unsigned char aChunk[3];
|
||||
|
||||
|
||||
if(!m_File)
|
||||
return;
|
||||
|
||||
|
@ -183,8 +183,8 @@ void CDemoRecorder::Write(int Type, const void *pData, int Size)
|
|||
aBuffer2[Size++] = 0;
|
||||
Size = CVariableInt::Compress(aBuffer2, Size, aBuffer); // buffer2 -> buffer
|
||||
Size = CNetBase::Compress(aBuffer, Size, aBuffer2, sizeof(aBuffer2)); // buffer -> buffer2
|
||||
|
||||
|
||||
|
||||
|
||||
aChunk[0] = ((Type&0x3)<<5);
|
||||
if(Size < 30)
|
||||
{
|
||||
|
@ -207,7 +207,7 @@ void CDemoRecorder::Write(int Type, const void *pData, int Size)
|
|||
io_write(m_File, aChunk, 3);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
io_write(m_File, aBuffer2, Size);
|
||||
}
|
||||
|
||||
|
@ -217,10 +217,10 @@ void CDemoRecorder::RecordSnapshot(int Tick, const void *pData, int Size)
|
|||
{
|
||||
// write full tickmarker
|
||||
WriteTickMarker(Tick, 1);
|
||||
|
||||
|
||||
// write snapshot
|
||||
Write(CHUNKTYPE_SNAPSHOT, pData, Size);
|
||||
|
||||
|
||||
m_LastKeyFrame = Tick;
|
||||
mem_copy(m_aLastSnapshotData, pData, Size);
|
||||
}
|
||||
|
@ -232,7 +232,7 @@ void CDemoRecorder::RecordSnapshot(int Tick, const void *pData, int Size)
|
|||
|
||||
// write tickmarker
|
||||
WriteTickMarker(Tick, 0);
|
||||
|
||||
|
||||
DeltaSize = m_pSnapshotDelta->CreateDelta((CSnapshot*)m_aLastSnapshotData, (CSnapshot*)pData, &aDeltaData);
|
||||
if(DeltaSize)
|
||||
{
|
||||
|
@ -262,7 +262,7 @@ int CDemoRecorder::Stop()
|
|||
aLength[2] = (DemoLength>>8)&0xff;
|
||||
aLength[3] = (DemoLength)&0xff;
|
||||
io_write(m_File, aLength, sizeof(aLength));
|
||||
|
||||
|
||||
io_close(m_File);
|
||||
m_File = 0;
|
||||
m_pConsole->Print(IConsole::OUTPUT_LEVEL_STANDARD, "demo_recorder", "Stopped recording");
|
||||
|
@ -290,19 +290,19 @@ void CDemoPlayer::SetListner(IListner *pListner)
|
|||
int CDemoPlayer::ReadChunkHeader(int *pType, int *pSize, int *pTick)
|
||||
{
|
||||
unsigned char Chunk = 0;
|
||||
|
||||
|
||||
*pSize = 0;
|
||||
*pType = 0;
|
||||
|
||||
|
||||
if(io_read(m_File, &Chunk, sizeof(Chunk)) != sizeof(Chunk))
|
||||
return -1;
|
||||
|
||||
|
||||
if(Chunk&CHUNKTYPEFLAG_TICKMARKER)
|
||||
{
|
||||
// decode tick marker
|
||||
int Tickdelta = Chunk&(CHUNKMASK_TICK);
|
||||
*pType = Chunk&(CHUNKTYPEFLAG_TICKMARKER|CHUNKTICKFLAG_KEYFRAME);
|
||||
|
||||
|
||||
if(Tickdelta == 0)
|
||||
{
|
||||
unsigned char aTickdata[4];
|
||||
|
@ -314,21 +314,21 @@ int CDemoPlayer::ReadChunkHeader(int *pType, int *pSize, int *pTick)
|
|||
{
|
||||
*pTick += Tickdelta;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
// decode normal chunk
|
||||
*pType = (Chunk&CHUNKMASK_TYPE)>>5;
|
||||
*pSize = Chunk&CHUNKMASK_SIZE;
|
||||
|
||||
|
||||
if(*pSize == 30)
|
||||
{
|
||||
unsigned char aSizedata[1];
|
||||
if(io_read(m_File, aSizedata, sizeof(aSizedata)) != sizeof(aSizedata))
|
||||
return -1;
|
||||
*pSize = aSizedata[0];
|
||||
|
||||
|
||||
}
|
||||
else if(*pSize == 31)
|
||||
{
|
||||
|
@ -338,7 +338,7 @@ int CDemoPlayer::ReadChunkHeader(int *pType, int *pSize, int *pTick)
|
|||
*pSize = (aSizedata[1]<<8) | aSizedata[0];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -358,17 +358,17 @@ void CDemoPlayer::ScanFile()
|
|||
while(1)
|
||||
{
|
||||
long CurrentPos = io_tell(m_File);
|
||||
|
||||
|
||||
if(ReadChunkHeader(&ChunkType, &ChunkSize, &ChunkTick))
|
||||
break;
|
||||
|
||||
|
||||
// read the chunk
|
||||
if(ChunkType&CHUNKTYPEFLAG_TICKMARKER)
|
||||
{
|
||||
if(ChunkType&CHUNKTICKFLAG_KEYFRAME)
|
||||
{
|
||||
CKeyFrameSearch *pKey;
|
||||
|
||||
|
||||
// save the position
|
||||
pKey = (CKeyFrameSearch *)Heap.Allocate(sizeof(CKeyFrameSearch));
|
||||
pKey->m_Frame.m_Filepos = CurrentPos;
|
||||
|
@ -381,21 +381,21 @@ void CDemoPlayer::ScanFile()
|
|||
pCurrentKey = pKey;
|
||||
m_Info.m_SeekablePoints++;
|
||||
}
|
||||
|
||||
|
||||
if(m_Info.m_Info.m_FirstTick == -1)
|
||||
m_Info.m_Info.m_FirstTick = ChunkTick;
|
||||
m_Info.m_Info.m_LastTick = ChunkTick;
|
||||
}
|
||||
else if(ChunkSize)
|
||||
io_skip(m_File, ChunkSize);
|
||||
|
||||
|
||||
}
|
||||
|
||||
// copy all the frames to an array instead for fast access
|
||||
m_pKeyFrames = (CKeyFrame*)mem_alloc(m_Info.m_SeekablePoints*sizeof(CKeyFrame), 1);
|
||||
for(pCurrentKey = pFirstKey, i = 0; pCurrentKey; pCurrentKey = pCurrentKey->m_pNext, i++)
|
||||
m_pKeyFrames[i] = pCurrentKey->m_Frame;
|
||||
|
||||
|
||||
// destroy the temporary heap and seek back to the start
|
||||
io_seek(m_File, StartPos, IOSEEK_START);
|
||||
}
|
||||
|
@ -429,7 +429,7 @@ void CDemoPlayer::DoTick()
|
|||
Pause();
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
// read the chunk
|
||||
if(ChunkSize)
|
||||
{
|
||||
|
@ -440,7 +440,7 @@ void CDemoPlayer::DoTick()
|
|||
Stop();
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
DataSize = CNetBase::Decompress(aCompresseddata, ChunkSize, aDecompressed, sizeof(aDecompressed));
|
||||
if(DataSize < 0)
|
||||
{
|
||||
|
@ -449,7 +449,7 @@ void CDemoPlayer::DoTick()
|
|||
Stop();
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
DataSize = CVariableInt::Decompress(aDecompressed, DataSize, aData);
|
||||
|
||||
if(DataSize < 0)
|
||||
|
@ -459,16 +459,16 @@ void CDemoPlayer::DoTick()
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(ChunkType == CHUNKTYPE_DELTA)
|
||||
{
|
||||
// process delta snapshot
|
||||
static char aNewsnap[CSnapshot::MAX_SIZE];
|
||||
|
||||
|
||||
GotSnapshot = 1;
|
||||
|
||||
|
||||
DataSize = m_pSnapshotDelta->UnpackDelta((CSnapshot*)m_aLastSnapshotData, (CSnapshot*)aNewsnap, aData, DataSize);
|
||||
|
||||
|
||||
if(DataSize >= 0)
|
||||
{
|
||||
if(m_pListner)
|
||||
|
@ -488,7 +488,7 @@ void CDemoPlayer::DoTick()
|
|||
{
|
||||
// process full snapshot
|
||||
GotSnapshot = 1;
|
||||
|
||||
|
||||
m_LastSnapshotDataSize = DataSize;
|
||||
mem_copy(m_aLastSnapshotData, aData, DataSize);
|
||||
if(m_pListner)
|
||||
|
@ -502,7 +502,7 @@ void CDemoPlayer::DoTick()
|
|||
GotSnapshot = 1;
|
||||
m_pListner->OnDemoPlayerSnapshot(m_aLastSnapshotData, m_LastSnapshotDataSize);
|
||||
}
|
||||
|
||||
|
||||
// check the remaining types
|
||||
if(ChunkType&CHUNKTYPEFLAG_TICKMARKER)
|
||||
{
|
||||
|
@ -544,7 +544,7 @@ int CDemoPlayer::Load(class IStorage *pStorage, class IConsole *pConsole, const
|
|||
m_pConsole->Print(IConsole::OUTPUT_LEVEL_STANDARD, "demo_player", aBuf);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
// store the filename
|
||||
str_copy(m_aFilename, pFilename, sizeof(m_aFilename));
|
||||
|
||||
|
@ -556,7 +556,7 @@ int CDemoPlayer::Load(class IStorage *pStorage, class IConsole *pConsole, const
|
|||
m_Info.m_Info.m_CurrentTick = -1;
|
||||
m_Info.m_PreviousTick = -1;
|
||||
m_Info.m_Info.m_Speed = 1;
|
||||
|
||||
|
||||
m_LastSnapshotDataSize = -1;
|
||||
|
||||
// read the header
|
||||
|
@ -580,7 +580,7 @@ int CDemoPlayer::Load(class IStorage *pStorage, class IConsole *pConsole, const
|
|||
m_File = 0;
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
// get demo type
|
||||
if(!str_comp(m_Info.m_Header.m_aType, "client"))
|
||||
m_DemoType = DEMOTYPE_CLIENT;
|
||||
|
@ -588,17 +588,17 @@ int CDemoPlayer::Load(class IStorage *pStorage, class IConsole *pConsole, const
|
|||
m_DemoType = DEMOTYPE_SERVER;
|
||||
else
|
||||
m_DemoType = DEMOTYPE_INVALID;
|
||||
|
||||
|
||||
// read map
|
||||
unsigned MapSize = (m_Info.m_Header.m_aMapSize[0]<<24) | (m_Info.m_Header.m_aMapSize[1]<<16) | (m_Info.m_Header.m_aMapSize[2]<<8) | (m_Info.m_Header.m_aMapSize[3]);
|
||||
|
||||
|
||||
// check if we already have the map
|
||||
// TODO: improve map checking (maps folder, check crc)
|
||||
unsigned Crc = (m_Info.m_Header.m_aMapCrc[0]<<24) | (m_Info.m_Header.m_aMapCrc[1]<<16) | (m_Info.m_Header.m_aMapCrc[2]<<8) | (m_Info.m_Header.m_aMapCrc[3]);
|
||||
char aMapFilename[128];
|
||||
str_format(aMapFilename, sizeof(aMapFilename), "downloadedmaps/%s_%08x.map", m_Info.m_Header.m_aMapName, Crc);
|
||||
IOHANDLE MapFile = pStorage->OpenFile(aMapFilename, IOFLAG_READ, IStorage::TYPE_ALL);
|
||||
|
||||
|
||||
if(MapFile)
|
||||
{
|
||||
io_skip(m_File, MapSize);
|
||||
|
@ -609,20 +609,20 @@ int CDemoPlayer::Load(class IStorage *pStorage, class IConsole *pConsole, const
|
|||
// get map data
|
||||
unsigned char *pMapData = (unsigned char *)mem_alloc(MapSize, 1);
|
||||
io_read(m_File, pMapData, MapSize);
|
||||
|
||||
|
||||
// save map
|
||||
MapFile = pStorage->OpenFile(aMapFilename, IOFLAG_WRITE, IStorage::TYPE_SAVE);
|
||||
io_write(MapFile, pMapData, MapSize);
|
||||
io_close(MapFile);
|
||||
|
||||
|
||||
// free data
|
||||
mem_free(pMapData);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// scan the file for interessting points
|
||||
ScanFile();
|
||||
|
||||
|
||||
// ready for playback
|
||||
return 0;
|
||||
}
|
||||
|
@ -638,7 +638,7 @@ int CDemoPlayer::Play()
|
|||
// fill in previous and next tick
|
||||
while(m_Info.m_PreviousTick == -1 && IsPlaying())
|
||||
DoTick();
|
||||
|
||||
|
||||
// set start info
|
||||
/*m_Info.start_tick = m_Info.previous_tick;
|
||||
m_Info.start_time = time_get();*/
|
||||
|
@ -653,15 +653,15 @@ int CDemoPlayer::SetPos(float Percent)
|
|||
int WantedTick;
|
||||
if(!m_File)
|
||||
return -1;
|
||||
|
||||
|
||||
// -5 because we have to have a current tick and previous tick when we do the playback
|
||||
WantedTick = m_Info.m_Info.m_FirstTick + (int)((m_Info.m_Info.m_LastTick-m_Info.m_Info.m_FirstTick)*Percent) - 5;
|
||||
|
||||
|
||||
Keyframe = (int)(m_Info.m_SeekablePoints*Percent);
|
||||
|
||||
if(Keyframe < 0 || Keyframe >= m_Info.m_SeekablePoints)
|
||||
return -1;
|
||||
|
||||
|
||||
// get correct key frame
|
||||
if(m_pKeyFrames[Keyframe].m_Tick < WantedTick)
|
||||
while(Keyframe < m_Info.m_SeekablePoints-1 && m_pKeyFrames[Keyframe].m_Tick < WantedTick)
|
||||
|
@ -669,7 +669,7 @@ int CDemoPlayer::SetPos(float Percent)
|
|||
|
||||
while(Keyframe && m_pKeyFrames[Keyframe].m_Tick > WantedTick)
|
||||
Keyframe--;
|
||||
|
||||
|
||||
// seek to the correct keyframe
|
||||
io_seek(m_File, m_pKeyFrames[Keyframe].m_Filepos, IOSEEK_START);
|
||||
|
||||
|
@ -681,9 +681,9 @@ int CDemoPlayer::SetPos(float Percent)
|
|||
// playback everything until we hit our tick
|
||||
while(m_Info.m_PreviousTick < WantedTick)
|
||||
DoTick();
|
||||
|
||||
|
||||
Play();
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -697,19 +697,19 @@ int CDemoPlayer::Update()
|
|||
int64 Now = time_get();
|
||||
int64 Deltatime = Now-m_Info.m_LastUpdate;
|
||||
m_Info.m_LastUpdate = Now;
|
||||
|
||||
|
||||
if(!IsPlaying())
|
||||
return 0;
|
||||
|
||||
|
||||
if(m_Info.m_Info.m_Paused)
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
int64 Freq = time_freq();
|
||||
m_Info.m_CurrentTime += (int64)(Deltatime*(double)m_Info.m_Info.m_Speed);
|
||||
|
||||
|
||||
while(1)
|
||||
{
|
||||
int64 CurtickStart = (m_Info.m_Info.m_CurrentTick)*Freq/SERVER_TICK_SPEED;
|
||||
|
@ -717,22 +717,22 @@ int CDemoPlayer::Update()
|
|||
// break if we are ready
|
||||
if(CurtickStart > m_Info.m_CurrentTime)
|
||||
break;
|
||||
|
||||
|
||||
// do one more tick
|
||||
DoTick();
|
||||
|
||||
|
||||
if(m_Info.m_Info.m_Paused)
|
||||
return 0;
|
||||
}
|
||||
|
||||
// update intratick
|
||||
{
|
||||
{
|
||||
int64 CurtickStart = (m_Info.m_Info.m_CurrentTick)*Freq/SERVER_TICK_SPEED;
|
||||
int64 PrevtickStart = (m_Info.m_PreviousTick)*Freq/SERVER_TICK_SPEED;
|
||||
m_Info.m_IntraTick = (m_Info.m_CurrentTime - PrevtickStart) / (float)(CurtickStart-PrevtickStart);
|
||||
m_Info.m_TickTime = (m_Info.m_CurrentTime - PrevtickStart) / (float)Freq;
|
||||
}
|
||||
|
||||
|
||||
if(m_Info.m_Info.m_CurrentTick == m_Info.m_PreviousTick ||
|
||||
m_Info.m_Info.m_CurrentTick == m_Info.m_NextTick)
|
||||
{
|
||||
|
@ -742,7 +742,7 @@ int CDemoPlayer::Update()
|
|||
m_pConsole->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "demo_player", aBuf);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -750,7 +750,7 @@ int CDemoPlayer::Stop()
|
|||
{
|
||||
if(!m_File)
|
||||
return -1;
|
||||
|
||||
|
||||
m_pConsole->Print(IConsole::OUTPUT_LEVEL_STANDARD, "demo_player", "Stopped playback");
|
||||
io_close(m_File);
|
||||
m_File = 0;
|
||||
|
@ -776,20 +776,20 @@ bool CDemoPlayer::GetDemoInfo(class IStorage *pStorage, const char *pFilename, i
|
|||
{
|
||||
if(!pDemoHeader)
|
||||
return false;
|
||||
|
||||
|
||||
mem_zero(pDemoHeader, sizeof(CDemoHeader));
|
||||
|
||||
IOHANDLE File = pStorage->OpenFile(pFilename, IOFLAG_READ, StorageType);
|
||||
if(!File)
|
||||
return false;
|
||||
|
||||
|
||||
io_read(File, pDemoHeader, sizeof(CDemoHeader));
|
||||
if(mem_comp(pDemoHeader->m_aMarker, gs_aHeaderMarker, sizeof(gs_aHeaderMarker)) || pDemoHeader->m_Version < gs_ActVersion)
|
||||
{
|
||||
io_close(File);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
io_close(File);
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -17,12 +17,12 @@ class CDemoRecorder : public IDemoRecorder
|
|||
int m_FirstTick;
|
||||
unsigned char m_aLastSnapshotData[CSnapshot::MAX_SIZE];
|
||||
class CSnapshotDelta *m_pSnapshotDelta;
|
||||
|
||||
|
||||
void WriteTickMarker(int Tick, int Keyframe);
|
||||
void Write(int Type, const void *pData, int Size);
|
||||
public:
|
||||
CDemoRecorder(class CSnapshotDelta *pSnapshotDelta);
|
||||
|
||||
|
||||
int Start(class IStorage *pStorage, class IConsole *pConsole, const char *pFilename, const char *pNetversion, const char *pMap, unsigned MapCrc, const char *pType);
|
||||
int Stop();
|
||||
|
||||
|
@ -44,21 +44,21 @@ public:
|
|||
virtual void OnDemoPlayerSnapshot(void *pData, int Size) = 0;
|
||||
virtual void OnDemoPlayerMessage(void *pData, int Size) = 0;
|
||||
};
|
||||
|
||||
|
||||
struct CPlaybackInfo
|
||||
{
|
||||
CDemoHeader m_Header;
|
||||
|
||||
|
||||
IDemoPlayer::CInfo m_Info;
|
||||
|
||||
int64 m_LastUpdate;
|
||||
int64 m_CurrentTime;
|
||||
|
||||
|
||||
int m_SeekablePoints;
|
||||
|
||||
|
||||
int m_NextTick;
|
||||
int m_PreviousTick;
|
||||
|
||||
|
||||
float m_IntraTick;
|
||||
float m_TickTime;
|
||||
};
|
||||
|
@ -73,12 +73,12 @@ private:
|
|||
long m_Filepos;
|
||||
int m_Tick;
|
||||
};
|
||||
|
||||
|
||||
struct CKeyFrameSearch
|
||||
{
|
||||
CKeyFrame m_Frame;
|
||||
CKeyFrameSearch *m_pNext;
|
||||
};
|
||||
};
|
||||
|
||||
class IConsole *m_pConsole;
|
||||
IOHANDLE m_File;
|
||||
|
@ -97,25 +97,25 @@ private:
|
|||
int NextFrame();
|
||||
|
||||
public:
|
||||
|
||||
|
||||
CDemoPlayer(class CSnapshotDelta *m_pSnapshotDelta);
|
||||
|
||||
|
||||
void SetListner(IListner *pListner);
|
||||
|
||||
|
||||
int Load(class IStorage *pStorage, class IConsole *pConsole, const char *pFilename, int StorageType);
|
||||
int Play();
|
||||
void Pause();
|
||||
void Unpause();
|
||||
int Stop();
|
||||
int Stop();
|
||||
void SetSpeed(float Speed);
|
||||
int SetPos(float Precent);
|
||||
const CInfo *BaseInfo() const { return &m_Info.m_Info; }
|
||||
char *GetDemoName();
|
||||
bool GetDemoInfo(class IStorage *pStorage, const char *pFilename, int StorageType, CDemoHeader *pDemoHeader) const;
|
||||
int GetDemoType() const;
|
||||
|
||||
|
||||
int Update();
|
||||
|
||||
|
||||
const CPlaybackInfo *Info() const { return &m_Info; }
|
||||
int IsPlaying() const { return m_File != 0; }
|
||||
};
|
||||
|
|
|
@ -43,7 +43,7 @@ public:
|
|||
pEngine->m_Logging = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
{
|
||||
char aBuf[32];
|
||||
str_timestamp(aBuf, sizeof(aBuf));
|
||||
char aFilenameSent[128], aFilenameRecv[128];
|
||||
|
@ -59,7 +59,7 @@ public:
|
|||
{
|
||||
dbg_logger_stdout();
|
||||
dbg_logger_debugger();
|
||||
|
||||
|
||||
//
|
||||
dbg_msg("engine", "running on %s-%s-%s", CONF_FAMILY_STRING, CONF_PLATFORM_STRING, CONF_ARCH_STRING);
|
||||
#ifdef CONF_ARCH_ENDIAN_LITTLE
|
||||
|
@ -73,7 +73,7 @@ public:
|
|||
// init the network
|
||||
net_init();
|
||||
CNetBase::Init();
|
||||
|
||||
|
||||
m_JobPool.Init(1);
|
||||
|
||||
m_Logging = false;
|
||||
|
|
|
@ -15,7 +15,7 @@ void CHuffman::Setbits_r(CNode *pNode, int Bits, unsigned Depth)
|
|||
Setbits_r(&m_aNodes[pNode->m_aLeafs[1]], Bits|(1<<Depth), Depth+1);
|
||||
if(pNode->m_aLeafs[0] != 0xffff)
|
||||
Setbits_r(&m_aNodes[pNode->m_aLeafs[0]], Bits, Depth+1);
|
||||
|
||||
|
||||
if(pNode->m_NumBits)
|
||||
{
|
||||
pNode->m_Bits = Bits;
|
||||
|
@ -28,7 +28,7 @@ static void BubbleSort(CHuffmanConstructNode **ppList, int Size)
|
|||
{
|
||||
int Changed = 1;
|
||||
CHuffmanConstructNode *pTemp;
|
||||
|
||||
|
||||
while(Changed)
|
||||
{
|
||||
Changed = 0;
|
||||
|
@ -68,15 +68,15 @@ void CHuffman::ConstructTree(const unsigned *pFrequencies)
|
|||
apNodesLeft[i] = &aNodesLeftStorage[i];
|
||||
|
||||
}
|
||||
|
||||
|
||||
m_NumNodes = HUFFMAN_MAX_SYMBOLS;
|
||||
|
||||
|
||||
// construct the table
|
||||
while(NumNodesLeft > 1)
|
||||
{
|
||||
// we can't rely on stdlib's qsort for this, it can generate different results on different implementations
|
||||
BubbleSort(apNodesLeft, NumNodesLeft);
|
||||
|
||||
|
||||
m_aNodes[m_NumNodes].m_NumBits = 0;
|
||||
m_aNodes[m_NumNodes].m_aLeafs[0] = apNodesLeft[NumNodesLeft-1]->m_NodeId;
|
||||
m_aNodes[m_NumNodes].m_aLeafs[1] = apNodesLeft[NumNodesLeft-2]->m_NodeId;
|
||||
|
@ -89,7 +89,7 @@ void CHuffman::ConstructTree(const unsigned *pFrequencies)
|
|||
|
||||
// set start node
|
||||
m_pStartNode = &m_aNodes[m_NumNodes-1];
|
||||
|
||||
|
||||
// build symbol bits
|
||||
Setbits_r(m_pStartNode, 0, 0);
|
||||
}
|
||||
|
@ -230,7 +230,7 @@ int CHuffman::Decompress(const void *pInput, int InputSize, void *pOutput, int O
|
|||
// {C} load symbol now if we didn't that earlier at location {A}
|
||||
if(!pNode)
|
||||
pNode = m_apDecodeLut[Bits&HUFFMAN_LUTMASK];
|
||||
|
||||
|
||||
if(!pNode)
|
||||
return -1;
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ class CHuffman
|
|||
|
||||
HUFFMAN_MAX_SYMBOLS=HUFFMAN_EOF_SYMBOL+1,
|
||||
HUFFMAN_MAX_NODES=HUFFMAN_MAX_SYMBOLS*2-1,
|
||||
|
||||
|
||||
HUFFMAN_LUTBITS = 10,
|
||||
HUFFMAN_LUTSIZE = (1<<HUFFMAN_LUTBITS),
|
||||
HUFFMAN_LUTMASK = (HUFFMAN_LUTSIZE-1)
|
||||
|
@ -36,10 +36,10 @@ class CHuffman
|
|||
CNode *m_apDecodeLut[HUFFMAN_LUTSIZE];
|
||||
CNode *m_pStartNode;
|
||||
int m_NumNodes;
|
||||
|
||||
|
||||
void Setbits_r(CNode *pNode, int Bits, unsigned Depth);
|
||||
void ConstructTree(const unsigned *pFrequencies);
|
||||
|
||||
|
||||
public:
|
||||
/*
|
||||
Function: huffman_init
|
||||
|
@ -86,6 +86,6 @@ public:
|
|||
Returns the size of the uncompressed data. Negative value on failure.
|
||||
*/
|
||||
int Decompress(const void *pInput, int InputSize, void *pOutput, int OutputSize);
|
||||
|
||||
|
||||
};
|
||||
#endif // __HUFFMAN_HEADER__
|
||||
|
|
|
@ -14,11 +14,11 @@ CJobPool::CJobPool()
|
|||
void CJobPool::WorkerThread(void *pUser)
|
||||
{
|
||||
CJobPool *pPool = (CJobPool *)pUser;
|
||||
|
||||
|
||||
while(1)
|
||||
{
|
||||
CJob *pJob = 0;
|
||||
|
||||
|
||||
// fetch job from queue
|
||||
lock_wait(pPool->m_Lock);
|
||||
if(pPool->m_pFirstJob)
|
||||
|
@ -31,7 +31,7 @@ void CJobPool::WorkerThread(void *pUser)
|
|||
pPool->m_pLastJob = 0;
|
||||
}
|
||||
lock_release(pPool->m_Lock);
|
||||
|
||||
|
||||
// do the job if we have one
|
||||
if(pJob)
|
||||
{
|
||||
|
@ -42,7 +42,7 @@ void CJobPool::WorkerThread(void *pUser)
|
|||
else
|
||||
thread_sleep(10);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
int CJobPool::Init(int NumThreads)
|
||||
|
@ -58,9 +58,9 @@ int CJobPool::Add(CJob *pJob, JOBFUNC pfnFunc, void *pData)
|
|||
mem_zero(pJob, sizeof(CJob));
|
||||
pJob->m_pfnFunc = pfnFunc;
|
||||
pJob->m_pFuncData = pData;
|
||||
|
||||
|
||||
lock_wait(m_Lock);
|
||||
|
||||
|
||||
// add job to queue
|
||||
pJob->m_pPrev = m_pLastJob;
|
||||
if(m_pLastJob)
|
||||
|
@ -68,7 +68,7 @@ int CJobPool::Add(CJob *pJob, JOBFUNC pfnFunc, void *pData)
|
|||
m_pLastJob = pJob;
|
||||
if(!m_pFirstJob)
|
||||
m_pFirstJob = pJob;
|
||||
|
||||
|
||||
lock_release(m_Lock);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -9,14 +9,14 @@ class CJobPool;
|
|||
class CJob
|
||||
{
|
||||
friend class CJobPool;
|
||||
|
||||
|
||||
CJobPool *m_pPool;
|
||||
CJob *m_pPrev;
|
||||
CJob *m_pNext;
|
||||
|
||||
|
||||
volatile int m_Status;
|
||||
volatile int m_Result;
|
||||
|
||||
|
||||
JOBFUNC m_pfnFunc;
|
||||
void *m_pFuncData;
|
||||
public:
|
||||
|
@ -25,14 +25,14 @@ public:
|
|||
m_Status = STATE_DONE;
|
||||
m_pFuncData = 0;
|
||||
}
|
||||
|
||||
|
||||
enum
|
||||
{
|
||||
STATE_PENDING=0,
|
||||
STATE_RUNNING,
|
||||
STATE_DONE
|
||||
};
|
||||
|
||||
|
||||
int Status() const { return m_Status; }
|
||||
int Result() const {return m_Result; }
|
||||
};
|
||||
|
@ -42,12 +42,12 @@ class CJobPool
|
|||
LOCK m_Lock;
|
||||
CJob *m_pFirstJob;
|
||||
CJob *m_pLastJob;
|
||||
|
||||
|
||||
static void WorkerThread(void *pUser);
|
||||
|
||||
|
||||
public:
|
||||
CJobPool();
|
||||
|
||||
|
||||
int Init(int NumThreads);
|
||||
int Add(CJob *pJob, JOBFUNC pfnFunc, void *pData);
|
||||
};
|
||||
|
|
|
@ -9,7 +9,7 @@ class CKernel : public IKernel
|
|||
{
|
||||
MAX_INTERFACES=32,
|
||||
};
|
||||
|
||||
|
||||
class CInterfaceInfo
|
||||
{
|
||||
public:
|
||||
|
@ -18,14 +18,14 @@ class CKernel : public IKernel
|
|||
m_aName[0] = 0;
|
||||
m_pInterface = 0x0;
|
||||
}
|
||||
|
||||
|
||||
char m_aName[64];
|
||||
IInterface *m_pInterface;
|
||||
};
|
||||
|
||||
CInterfaceInfo m_aInterfaces[MAX_INTERFACES];
|
||||
int m_NumInterfaces;
|
||||
|
||||
|
||||
CInterfaceInfo *FindInterfaceInfo(const char *pName)
|
||||
{
|
||||
for(int i = 0; i < m_NumInterfaces; i++)
|
||||
|
@ -35,7 +35,7 @@ class CKernel : public IKernel
|
|||
}
|
||||
return 0x0;
|
||||
}
|
||||
|
||||
|
||||
public:
|
||||
|
||||
CKernel()
|
||||
|
@ -58,18 +58,18 @@ public:
|
|||
dbg_msg("kernel", "ERROR: couldn't register interface '%s'. maximum of interfaces reached", pName);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
if(FindInterfaceInfo(pName) != 0)
|
||||
{
|
||||
dbg_msg("kernel", "ERROR: couldn't register interface '%s'. interface already exists", pName);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
pInterface->m_pKernel = this;
|
||||
m_aInterfaces[m_NumInterfaces].m_pInterface = pInterface;
|
||||
str_copy(m_aInterfaces[m_NumInterfaces].m_aName, pName, sizeof(m_aInterfaces[m_NumInterfaces].m_aName));
|
||||
m_NumInterfaces++;
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -80,12 +80,12 @@ public:
|
|||
dbg_msg("kernel", "ERROR: couldn't reregister interface '%s'. interface doesn't exist");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
pInterface->m_pKernel = this;
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
virtual IInterface *RequestInterfaceImpl(const char *pName)
|
||||
{
|
||||
CInterfaceInfo *pInfo = FindInterfaceInfo(pName);
|
||||
|
|
|
@ -10,7 +10,7 @@ class CMap : public IEngineMap
|
|||
CDataFileReader m_DataFile;
|
||||
public:
|
||||
CMap() {}
|
||||
|
||||
|
||||
virtual void *GetData(int Index) { return m_DataFile.GetData(Index); }
|
||||
virtual void *GetDataSwapped(int Index) { return m_DataFile.GetDataSwapped(Index); }
|
||||
virtual void UnloadData(int Index) { m_DataFile.UnloadData(Index); }
|
||||
|
@ -18,7 +18,7 @@ public:
|
|||
virtual void GetType(int Type, int *pStart, int *pNum) { m_DataFile.GetType(Type, pStart, pNum); }
|
||||
virtual void *FindItem(int Type, int ID) { return m_DataFile.FindItem(Type, ID); }
|
||||
virtual int NumItems() { return m_DataFile.NumItems(); }
|
||||
|
||||
|
||||
virtual void Unload()
|
||||
{
|
||||
m_DataFile.Close();
|
||||
|
@ -31,12 +31,12 @@ public:
|
|||
return false;
|
||||
return m_DataFile.Open(pStorage, pMapName, IStorage::TYPE_ALL);
|
||||
}
|
||||
|
||||
|
||||
virtual bool IsLoaded()
|
||||
{
|
||||
return m_DataFile.IsOpen();
|
||||
}
|
||||
|
||||
|
||||
virtual unsigned Crc()
|
||||
{
|
||||
return m_DataFile.Crc();
|
||||
|
|
|
@ -42,7 +42,7 @@ void CMapChecker::AddMaplist(CMapVersion *pMaplist, int Num)
|
|||
m_pFirst = pEntry;
|
||||
|
||||
str_copy(pEntry->m_aMapName, pMaplist[i].m_aName, sizeof(pEntry->m_aMapName));
|
||||
pEntry->m_MapCrc = (pMaplist[i].m_aCrc[0]<<24) | (pMaplist[i].m_aCrc[1]<<16) | (pMaplist[i].m_aCrc[2]<<8) | pMaplist[i].m_aCrc[3];
|
||||
pEntry->m_MapCrc = (pMaplist[i].m_aCrc[0]<<24) | (pMaplist[i].m_aCrc[1]<<16) | (pMaplist[i].m_aCrc[2]<<8) | pMaplist[i].m_aCrc[3];
|
||||
pEntry->m_MapSize = (pMaplist[i].m_aSize[0]<<24) | (pMaplist[i].m_aSize[1]<<16) | (pMaplist[i].m_aSize[2]<<8) | pMaplist[i].m_aSize[3];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ class CMapChecker
|
|||
unsigned m_MapSize;
|
||||
CWhitelistEntry *m_pNext;
|
||||
};
|
||||
|
||||
|
||||
class CHeap m_Whitelist;
|
||||
CWhitelistEntry *m_pFirst;
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@ public:
|
|||
char m_aHostname[128];
|
||||
NETADDR m_Addr;
|
||||
bool m_Valid;
|
||||
|
||||
|
||||
CHostLookup m_Lookup;
|
||||
} ;
|
||||
|
||||
|
@ -27,7 +27,7 @@ public:
|
|||
int m_NeedsUpdate;
|
||||
IEngine *m_pEngine;
|
||||
IStorage *m_pStorage;
|
||||
|
||||
|
||||
CMasterServer()
|
||||
{
|
||||
SetDefault();
|
||||
|
@ -38,10 +38,10 @@ public:
|
|||
virtual int RefreshAddresses(int Nettype)
|
||||
{
|
||||
int i;
|
||||
|
||||
|
||||
if(m_NeedsUpdate != -1)
|
||||
return 0;
|
||||
|
||||
|
||||
dbg_msg("engine/mastersrv", "refreshing master server addresses");
|
||||
|
||||
// add lookup jobs
|
||||
|
@ -50,7 +50,7 @@ public:
|
|||
m_pEngine->HostLookup(&m_aMasterServers[i].m_Lookup, m_aMasterServers[i].m_aHostname, Nettype);
|
||||
m_aMasterServers[i].m_Valid = false;
|
||||
}
|
||||
|
||||
|
||||
m_NeedsUpdate = 1;
|
||||
return 0;
|
||||
}
|
||||
|
@ -61,7 +61,7 @@ public:
|
|||
if(m_NeedsUpdate != 1)
|
||||
return;
|
||||
m_NeedsUpdate = 0;
|
||||
|
||||
|
||||
for(int i = 0; i < MAX_MASTERSERVERS; i++)
|
||||
{
|
||||
if(m_aMasterServers[i].m_Lookup.m_Job.Status() != CJob::STATE_DONE)
|
||||
|
@ -78,7 +78,7 @@ public:
|
|||
m_aMasterServers[i].m_Valid = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(!m_NeedsUpdate)
|
||||
{
|
||||
dbg_msg("engine/mastersrv", "saving addresses");
|
||||
|
@ -91,12 +91,12 @@ public:
|
|||
return m_NeedsUpdate;
|
||||
}
|
||||
|
||||
virtual NETADDR GetAddr(int Index)
|
||||
virtual NETADDR GetAddr(int Index)
|
||||
{
|
||||
return m_aMasterServers[Index].m_Addr;
|
||||
}
|
||||
|
||||
virtual const char *GetName(int Index)
|
||||
virtual const char *GetName(int Index)
|
||||
{
|
||||
return m_aMasterServers[Index].m_aHostname;
|
||||
}
|
||||
|
@ -136,12 +136,12 @@ public:
|
|||
int Count = 0;
|
||||
if(!m_pStorage)
|
||||
return -1;
|
||||
|
||||
|
||||
// try to open file
|
||||
File = m_pStorage->OpenFile("masters.cfg", IOFLAG_READ, IStorage::TYPE_SAVE);
|
||||
if(!File)
|
||||
return -1;
|
||||
|
||||
|
||||
LineReader.Init(File);
|
||||
while(1)
|
||||
{
|
||||
|
@ -166,7 +166,7 @@ public:
|
|||
//else
|
||||
// dbg_msg("engine/mastersrv", "warning: couldn't parse master server '%s'", pLine);
|
||||
}
|
||||
|
||||
|
||||
io_close(File);
|
||||
return 0;
|
||||
}
|
||||
|
@ -177,7 +177,7 @@ public:
|
|||
|
||||
if(!m_pStorage)
|
||||
return -1;
|
||||
|
||||
|
||||
// try to open file
|
||||
File = m_pStorage->OpenFile("masters.cfg", IOFLAG_WRITE, IStorage::TYPE_SAVE);
|
||||
if(!File)
|
||||
|
@ -189,10 +189,10 @@ public:
|
|||
net_addr_str(&m_aMasterServers[i].m_Addr, aAddrStr, sizeof(aAddrStr));
|
||||
char aBuf[1024];
|
||||
str_format(aBuf, sizeof(aBuf), "%s %s\n", m_aMasterServers[i].m_aHostname, aAddrStr);
|
||||
|
||||
|
||||
io_write(File, aBuf, str_length(aBuf));
|
||||
}
|
||||
|
||||
|
||||
io_close(File);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ void CHeap::NewChunk()
|
|||
{
|
||||
CChunk *pChunk;
|
||||
char *pMem;
|
||||
|
||||
|
||||
// allocate memory
|
||||
pMem = (char*)mem_alloc(sizeof(CChunk)+CHUNK_SIZE, 1);
|
||||
if(!pMem)
|
||||
|
@ -25,14 +25,14 @@ void CHeap::NewChunk()
|
|||
pChunk->m_pNext = (CChunk *)0x0;
|
||||
|
||||
pChunk->m_pNext = m_pCurrent;
|
||||
m_pCurrent = pChunk;
|
||||
m_pCurrent = pChunk;
|
||||
}
|
||||
|
||||
//****************
|
||||
void *CHeap::AllocateFromChunk(unsigned int Size)
|
||||
{
|
||||
char *pMem;
|
||||
|
||||
|
||||
// check if we need can fit the allocation
|
||||
if(m_pCurrent->m_pCurrent + Size > m_pCurrent->m_pEnd)
|
||||
return (void*)0x0;
|
||||
|
@ -66,14 +66,14 @@ void CHeap::Clear()
|
|||
{
|
||||
CChunk *pChunk = m_pCurrent;
|
||||
CChunk *pNext;
|
||||
|
||||
|
||||
while(pChunk)
|
||||
{
|
||||
pNext = pChunk->m_pNext;
|
||||
mem_free(pChunk);
|
||||
pChunk = pNext;
|
||||
}
|
||||
|
||||
|
||||
m_pCurrent = 0x0;
|
||||
}
|
||||
|
||||
|
@ -88,10 +88,10 @@ void *CHeap::Allocate(unsigned Size)
|
|||
{
|
||||
// allocate new chunk and add it to the heap
|
||||
NewChunk();
|
||||
|
||||
|
||||
// try to allocate again
|
||||
pMem = (char *)AllocateFromChunk(Size);
|
||||
}
|
||||
|
||||
|
||||
return pMem;
|
||||
}
|
||||
|
|
|
@ -11,20 +11,20 @@ class CHeap
|
|||
char *m_pEnd;
|
||||
CChunk *m_pNext;
|
||||
};
|
||||
|
||||
|
||||
enum
|
||||
{
|
||||
// how large each chunk should be
|
||||
CHUNK_SIZE = 1025*64,
|
||||
};
|
||||
|
||||
|
||||
CChunk *m_pCurrent;
|
||||
|
||||
|
||||
|
||||
|
||||
void Clear();
|
||||
void NewChunk();
|
||||
void *AllocateFromChunk(unsigned int Size);
|
||||
|
||||
|
||||
public:
|
||||
CHeap();
|
||||
~CHeap();
|
||||
|
|
|
@ -26,35 +26,35 @@ int CNetRecvUnpacker::FetchChunk(CNetChunk *pChunk)
|
|||
{
|
||||
CNetChunkHeader Header;
|
||||
unsigned char *pEnd = m_Data.m_aChunkData + m_Data.m_DataSize;
|
||||
|
||||
|
||||
while(1)
|
||||
{
|
||||
unsigned char *pData = m_Data.m_aChunkData;
|
||||
|
||||
|
||||
// check for old data to unpack
|
||||
if(!m_Valid || m_CurrentChunk >= m_Data.m_NumChunks)
|
||||
{
|
||||
Clear();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// TODO: add checking here so we don't read too far
|
||||
for(int i = 0; i < m_CurrentChunk; i++)
|
||||
{
|
||||
pData = Header.Unpack(pData);
|
||||
pData += Header.m_Size;
|
||||
}
|
||||
|
||||
|
||||
// unpack the header
|
||||
pData = Header.Unpack(pData);
|
||||
m_CurrentChunk++;
|
||||
|
||||
|
||||
if(pData+Header.m_Size > pEnd)
|
||||
{
|
||||
Clear();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// handle sequence stuff
|
||||
if(m_pConnection && (Header.m_Flags&NET_CHUNKFLAG_VITAL))
|
||||
{
|
||||
|
@ -76,7 +76,7 @@ int CNetRecvUnpacker::FetchChunk(CNetChunk *pChunk)
|
|||
continue; // take the next chunk in the packet
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// fill in the info
|
||||
pChunk->m_ClientID = m_ClientID;
|
||||
pChunk->m_Address = m_Addr;
|
||||
|
@ -116,7 +116,7 @@ void CNetBase::SendPacket(NETSOCKET Socket, NETADDR *pAddr, CNetPacketConstruct
|
|||
io_write(ms_DataLogSent, &pPacket->m_aChunkData, pPacket->m_DataSize);
|
||||
io_flush(ms_DataLogSent);
|
||||
}
|
||||
|
||||
|
||||
// compress
|
||||
CompressedSize = ms_Huffman.Compress(pPacket->m_aChunkData, pPacket->m_DataSize, &aBuffer[3], NET_MAX_PACKETSIZE-4);
|
||||
|
||||
|
@ -174,7 +174,7 @@ int CNetBase::UnpackPacket(unsigned char *pBuffer, int Size, CNetPacketConstruct
|
|||
io_write(ms_DataLogRecv, pBuffer, Size);
|
||||
io_flush(ms_DataLogRecv);
|
||||
}
|
||||
|
||||
|
||||
// read the packet
|
||||
pPacket->m_Flags = pBuffer[0]>>4;
|
||||
pPacket->m_Ack = ((pBuffer[0]&0xf)<<8) | pBuffer[1];
|
||||
|
@ -188,7 +188,7 @@ int CNetBase::UnpackPacket(unsigned char *pBuffer, int Size, CNetPacketConstruct
|
|||
dbg_msg("", "connection less packet too small, %d", Size);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
pPacket->m_Flags = NET_PACKETFLAG_CONNLESS;
|
||||
pPacket->m_Ack = 0;
|
||||
pPacket->m_NumChunks = 0;
|
||||
|
@ -220,7 +220,7 @@ int CNetBase::UnpackPacket(unsigned char *pBuffer, int Size, CNetPacketConstruct
|
|||
io_write(ms_DataLogRecv, pPacket->m_aChunkData, pPacket->m_DataSize);
|
||||
io_flush(ms_DataLogRecv);
|
||||
}
|
||||
|
||||
|
||||
// return success
|
||||
return 0;
|
||||
}
|
||||
|
@ -235,7 +235,7 @@ void CNetBase::SendControlMsg(NETSOCKET Socket, NETADDR *pAddr, int Ack, int Con
|
|||
Construct.m_DataSize = 1+ExtraSize;
|
||||
Construct.m_aChunkData[0] = ControlMsg;
|
||||
mem_copy(&Construct.m_aChunkData[1], pExtra, ExtraSize);
|
||||
|
||||
|
||||
// send the control message
|
||||
CNetBase::SendPacket(Socket, pAddr, &Construct);
|
||||
}
|
||||
|
@ -284,7 +284,7 @@ int CNetBase::IsSeqInBackroom(int Seq, int Ack)
|
|||
if(Seq <= Ack && Seq >= Bottom)
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ CURRENT:
|
|||
unsigned char flags_ack; // 4bit flags, 4bit ack
|
||||
unsigned char ack; // 8 bit ack
|
||||
unsigned char num_chunks; // 8 bit chunks
|
||||
|
||||
|
||||
(unsigned char padding[3]) // 24 bit extra incase it's a connection less packet
|
||||
// this is to make sure that it's compatible with the
|
||||
// old protocol
|
||||
|
@ -30,11 +30,11 @@ enum
|
|||
NETSENDFLAG_VITAL=1,
|
||||
NETSENDFLAG_CONNLESS=2,
|
||||
NETSENDFLAG_FLUSH=4,
|
||||
|
||||
|
||||
NETSTATE_OFFLINE=0,
|
||||
NETSTATE_CONNECTING,
|
||||
NETSTATE_ONLINE,
|
||||
|
||||
|
||||
NETBANTYPE_SOFT=1,
|
||||
NETBANTYPE_DROP=2
|
||||
};
|
||||
|
@ -65,17 +65,17 @@ enum
|
|||
|
||||
NET_CHUNKFLAG_VITAL=1,
|
||||
NET_CHUNKFLAG_RESEND=2,
|
||||
|
||||
|
||||
NET_CTRLMSG_KEEPALIVE=0,
|
||||
NET_CTRLMSG_CONNECT=1,
|
||||
NET_CTRLMSG_CONNECTACCEPT=2,
|
||||
NET_CTRLMSG_ACCEPT=3,
|
||||
NET_CTRLMSG_CLOSE=4,
|
||||
|
||||
|
||||
NET_SERVER_MAXBANS=1024,
|
||||
|
||||
|
||||
NET_CONN_BUFFERSIZE=1024*32,
|
||||
|
||||
|
||||
NET_ENUM_TERMINATOR
|
||||
};
|
||||
|
||||
|
@ -100,7 +100,7 @@ public:
|
|||
int m_Flags;
|
||||
int m_Size;
|
||||
int m_Sequence;
|
||||
|
||||
|
||||
unsigned char *Pack(unsigned char *pData);
|
||||
unsigned char *Unpack(unsigned char *pData);
|
||||
};
|
||||
|
@ -138,30 +138,30 @@ private:
|
|||
unsigned short m_Sequence;
|
||||
unsigned short m_Ack;
|
||||
unsigned m_State;
|
||||
|
||||
|
||||
int m_Token;
|
||||
int m_RemoteClosed;
|
||||
|
||||
|
||||
TStaticRingBuffer<CNetChunkResend, NET_CONN_BUFFERSIZE> m_Buffer;
|
||||
|
||||
|
||||
int64 m_LastUpdateTime;
|
||||
int64 m_LastRecvTime;
|
||||
int64 m_LastSendTime;
|
||||
|
||||
|
||||
char m_ErrorString[256];
|
||||
|
||||
|
||||
CNetPacketConstruct m_Construct;
|
||||
|
||||
|
||||
NETADDR m_PeerAddr;
|
||||
NETSOCKET m_Socket;
|
||||
NETSTATS m_Stats;
|
||||
|
||||
|
||||
//
|
||||
void Reset();
|
||||
void ResetStats();
|
||||
void SetError(const char *pString);
|
||||
void AckChunks(int Ack);
|
||||
|
||||
|
||||
int QueueChunkEx(int Flags, int DataSize, const void *pData, int Sequence);
|
||||
void SendControl(int ControlMsg, const void *pExtra, int ExtraSize);
|
||||
void ResendChunk(CNetChunkResend *pResend);
|
||||
|
@ -173,7 +173,7 @@ public:
|
|||
void Disconnect(const char *pReason);
|
||||
|
||||
int Update();
|
||||
int Flush();
|
||||
int Flush();
|
||||
|
||||
int Feed(CNetPacketConstruct *pPacket, NETADDR *pAddr);
|
||||
int QueueChunk(int Flags, int DataSize, const void *pData);
|
||||
|
@ -182,13 +182,13 @@ public:
|
|||
void SignalResend();
|
||||
int State() const { return m_State; }
|
||||
NETADDR PeerAddress() const { return m_PeerAddr; }
|
||||
|
||||
|
||||
void ResetErrorString() { m_ErrorString[0] = 0; }
|
||||
const char *ErrorString() const { return m_ErrorString; }
|
||||
|
||||
|
||||
// Needed for GotProblems in NetClient
|
||||
int64 LastRecvTime() const { return m_LastRecvTime; }
|
||||
|
||||
|
||||
int AckSequence() const { return m_Ack; }
|
||||
};
|
||||
|
||||
|
@ -196,7 +196,7 @@ struct CNetRecvUnpacker
|
|||
{
|
||||
public:
|
||||
bool m_Valid;
|
||||
|
||||
|
||||
NETADDR m_Addr;
|
||||
CNetConnection *m_pConnection;
|
||||
int m_CurrentChunk;
|
||||
|
@ -207,7 +207,7 @@ public:
|
|||
CNetRecvUnpacker() { Clear(); }
|
||||
void Clear();
|
||||
void Start(const NETADDR *pAddr, CNetConnection *pConnection, int ClientID);
|
||||
int FetchChunk(CNetChunk *pChunk);
|
||||
int FetchChunk(CNetChunk *pChunk);
|
||||
};
|
||||
|
||||
// server side
|
||||
|
@ -220,29 +220,29 @@ public:
|
|||
int m_Expires;
|
||||
char m_Reason[128];
|
||||
};
|
||||
|
||||
|
||||
private:
|
||||
class CSlot
|
||||
{
|
||||
public:
|
||||
CNetConnection m_Connection;
|
||||
};
|
||||
|
||||
|
||||
class CBan
|
||||
{
|
||||
public:
|
||||
CBanInfo m_Info;
|
||||
|
||||
|
||||
// hash list
|
||||
CBan *m_pHashNext;
|
||||
CBan *m_pHashPrev;
|
||||
|
||||
|
||||
// used or free list
|
||||
CBan *m_pNext;
|
||||
CBan *m_pPrev;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
NETSOCKET m_Socket;
|
||||
CSlot m_aSlots[NET_MAX_CLIENTS];
|
||||
int m_MaxClients;
|
||||
|
@ -256,23 +256,23 @@ private:
|
|||
NETFUNC_NEWCLIENT m_pfnNewClient;
|
||||
NETFUNC_DELCLIENT m_pfnDelClient;
|
||||
void *m_UserPtr;
|
||||
|
||||
|
||||
CNetRecvUnpacker m_RecvUnpacker;
|
||||
|
||||
|
||||
void BanRemoveByObject(CBan *pBan);
|
||||
|
||||
|
||||
public:
|
||||
int SetCallbacks(NETFUNC_NEWCLIENT pfnNewClient, NETFUNC_DELCLIENT pfnDelClient, void *pUser);
|
||||
|
||||
//
|
||||
bool Open(NETADDR BindAddr, int MaxClients, int MaxClientsPerIP, int Flags);
|
||||
int Close();
|
||||
|
||||
|
||||
//
|
||||
int Recv(CNetChunk *pChunk);
|
||||
int Send(CNetChunk *pChunk);
|
||||
int Update();
|
||||
|
||||
|
||||
//
|
||||
int Drop(int ClientID, const char *pReason);
|
||||
|
||||
|
@ -321,21 +321,21 @@ public:
|
|||
// openness
|
||||
bool Open(NETADDR BindAddr, int Flags);
|
||||
int Close();
|
||||
|
||||
|
||||
// connection state
|
||||
int Disconnect(const char *Reason);
|
||||
int Connect(NETADDR *Addr);
|
||||
|
||||
|
||||
// communication
|
||||
int Recv(CNetChunk *Chunk);
|
||||
int Send(CNetChunk *Chunk);
|
||||
|
||||
|
||||
// pumping
|
||||
int Update();
|
||||
int Flush();
|
||||
|
||||
int ResetErrorString();
|
||||
|
||||
|
||||
// error and state
|
||||
int State();
|
||||
int GotProblems();
|
||||
|
@ -356,14 +356,14 @@ public:
|
|||
static void Init();
|
||||
static int Compress(const void *pData, int DataSize, void *pOutput, int OutputSize);
|
||||
static int Decompress(const void *pData, int DataSize, void *pOutput, int OutputSize);
|
||||
|
||||
|
||||
static void SendControlMsg(NETSOCKET Socket, NETADDR *pAddr, int Ack, int ControlMsg, const void *pExtra, int ExtraSize);
|
||||
static void SendPacketConnless(NETSOCKET Socket, NETADDR *pAddr, const void *pData, int DataSize);
|
||||
static void SendPacket(NETSOCKET Socket, NETADDR *pAddr, CNetPacketConstruct *pPacket);
|
||||
static int UnpackPacket(unsigned char *pBuffer, int Size, CNetPacketConstruct *pPacket);
|
||||
|
||||
// The backroom is ack-NET_MAX_SEQUENCE/2. Used for knowing if we acked a packet or not
|
||||
static int IsSeqInBackroom(int Seq, int Ack);
|
||||
static int IsSeqInBackroom(int Seq, int Ack);
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -61,7 +61,7 @@ int CNetClient::Recv(CNetChunk *pChunk)
|
|||
// check for a chunk
|
||||
if(m_RecvUnpacker.FetchChunk(pChunk))
|
||||
return 1;
|
||||
|
||||
|
||||
// TODO: empty the recvinfo
|
||||
NETADDR Addr;
|
||||
int Bytes = net_udp_recv(m_Socket, &Addr, m_RecvUnpacker.m_aBuffer, NET_MAX_PACKETSIZE);
|
||||
|
@ -98,7 +98,7 @@ int CNetClient::Send(CNetChunk *pChunk)
|
|||
dbg_msg("netclient", "chunk payload too big. %d. dropping chunk", pChunk->m_DataSize);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
if(pChunk->m_Flags&NETSENDFLAG_CONNLESS)
|
||||
{
|
||||
// send connectionless packet
|
||||
|
@ -108,10 +108,10 @@ int CNetClient::Send(CNetChunk *pChunk)
|
|||
{
|
||||
int Flags = 0;
|
||||
dbg_assert(pChunk->m_ClientID == 0, "errornous client id");
|
||||
|
||||
|
||||
if(pChunk->m_Flags&NETSENDFLAG_VITAL)
|
||||
Flags = NET_CHUNKFLAG_VITAL;
|
||||
|
||||
|
||||
m_Connection.QueueChunk(Flags, pChunk->m_DataSize, pChunk->m_pData);
|
||||
|
||||
if(pChunk->m_Flags&NETSENDFLAG_FLUSH)
|
||||
|
|
|
@ -14,16 +14,16 @@ void CNetConnection::Reset()
|
|||
m_Sequence = 0;
|
||||
m_Ack = 0;
|
||||
m_RemoteClosed = 0;
|
||||
|
||||
|
||||
m_State = NET_CONNSTATE_OFFLINE;
|
||||
m_LastSendTime = 0;
|
||||
m_LastRecvTime = 0;
|
||||
m_LastUpdateTime = 0;
|
||||
m_Token = -1;
|
||||
mem_zero(&m_PeerAddr, sizeof(m_PeerAddr));
|
||||
|
||||
|
||||
m_Buffer.Init();
|
||||
|
||||
|
||||
mem_zero(&m_Construct, sizeof(m_Construct));
|
||||
}
|
||||
|
||||
|
@ -41,7 +41,7 @@ void CNetConnection::Init(NETSOCKET Socket)
|
|||
{
|
||||
Reset();
|
||||
ResetStats();
|
||||
|
||||
|
||||
m_Socket = Socket;
|
||||
mem_zero(m_ErrorString, sizeof(m_ErrorString));
|
||||
}
|
||||
|
@ -53,7 +53,7 @@ void CNetConnection::AckChunks(int Ack)
|
|||
CNetChunkResend *pResend = m_Buffer.First();
|
||||
if(!pResend)
|
||||
break;
|
||||
|
||||
|
||||
if(CNetBase::IsSeqInBackroom(pResend->m_Sequence, Ack))
|
||||
m_Buffer.PopFirst();
|
||||
else
|
||||
|
@ -75,10 +75,10 @@ int CNetConnection::Flush()
|
|||
// send of the packets
|
||||
m_Construct.m_Ack = m_Ack;
|
||||
CNetBase::SendPacket(m_Socket, &m_PeerAddr, &m_Construct);
|
||||
|
||||
|
||||
// update send times
|
||||
m_LastSendTime = time_get();
|
||||
|
||||
|
||||
// clear construct so we can start building a new package
|
||||
mem_zero(&m_Construct, sizeof(m_Construct));
|
||||
return NumChunks;
|
||||
|
@ -87,7 +87,7 @@ int CNetConnection::Flush()
|
|||
int CNetConnection::QueueChunkEx(int Flags, int DataSize, const void *pData, int Sequence)
|
||||
{
|
||||
unsigned char *pChunkData;
|
||||
|
||||
|
||||
// check if we have space for it, if not, flush the connection
|
||||
if(m_Construct.m_DataSize + DataSize + NET_MAX_CHUNKHEADERSIZE > (int)sizeof(m_Construct.m_aChunkData))
|
||||
Flush();
|
||||
|
@ -105,9 +105,9 @@ int CNetConnection::QueueChunkEx(int Flags, int DataSize, const void *pData, int
|
|||
//
|
||||
m_Construct.m_NumChunks++;
|
||||
m_Construct.m_DataSize = (int)(pChunkData-m_Construct.m_aChunkData);
|
||||
|
||||
|
||||
// set packet flags aswell
|
||||
|
||||
|
||||
if(Flags&NET_CHUNKFLAG_VITAL && !(Flags&NET_CHUNKFLAG_RESEND))
|
||||
{
|
||||
// save packet if we need to resend
|
||||
|
@ -163,7 +163,7 @@ int CNetConnection::Connect(NETADDR *pAddr)
|
|||
{
|
||||
if(State() != NET_CONNSTATE_OFFLINE)
|
||||
return -1;
|
||||
|
||||
|
||||
// init connection
|
||||
Reset();
|
||||
m_PeerAddr = *pAddr;
|
||||
|
@ -189,14 +189,14 @@ void CNetConnection::Disconnect(const char *pReason)
|
|||
if(pReason)
|
||||
str_copy(m_ErrorString, pReason, sizeof(m_ErrorString));
|
||||
}
|
||||
|
||||
|
||||
Reset();
|
||||
}
|
||||
|
||||
int CNetConnection::Feed(CNetPacketConstruct *pPacket, NETADDR *pAddr)
|
||||
{
|
||||
int64 Now = time_get();
|
||||
|
||||
|
||||
// check if resend is requested
|
||||
if(pPacket->m_Flags&NET_PACKETFLAG_RESEND)
|
||||
Resend();
|
||||
|
@ -205,14 +205,14 @@ int CNetConnection::Feed(CNetPacketConstruct *pPacket, NETADDR *pAddr)
|
|||
if(pPacket->m_Flags&NET_PACKETFLAG_CONTROL)
|
||||
{
|
||||
int CtrlMsg = pPacket->m_aChunkData[0];
|
||||
|
||||
|
||||
if(CtrlMsg == NET_CTRLMSG_CLOSE)
|
||||
{
|
||||
if(net_addr_comp(&m_PeerAddr, pAddr) == 0)
|
||||
{
|
||||
m_State = NET_CONNSTATE_ERROR;
|
||||
m_RemoteClosed = 1;
|
||||
|
||||
|
||||
if(pPacket->m_DataSize)
|
||||
{
|
||||
// make sure to sanitize the error string form the other party
|
||||
|
@ -222,17 +222,17 @@ int CNetConnection::Feed(CNetPacketConstruct *pPacket, NETADDR *pAddr)
|
|||
else
|
||||
str_copy(Str, (char *)pPacket->m_aChunkData, sizeof(Str));
|
||||
str_sanitize_strong(Str);
|
||||
|
||||
|
||||
// set the error string
|
||||
SetError(Str);
|
||||
}
|
||||
else
|
||||
SetError("No reason given");
|
||||
|
||||
|
||||
if(g_Config.m_Debug)
|
||||
dbg_msg("conn", "closed reason='%s'", ErrorString());
|
||||
}
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -249,7 +249,7 @@ int CNetConnection::Feed(CNetPacketConstruct *pPacket, NETADDR *pAddr)
|
|||
m_LastUpdateTime = Now;
|
||||
SendControl(NET_CTRLMSG_CONNECTACCEPT, 0, 0);
|
||||
if(g_Config.m_Debug)
|
||||
dbg_msg("connection", "got connection, sending connect+accept");
|
||||
dbg_msg("connection", "got connection, sending connect+accept");
|
||||
}
|
||||
}
|
||||
else if(State() == NET_CONNSTATE_CONNECT)
|
||||
|
@ -276,13 +276,13 @@ int CNetConnection::Feed(CNetPacketConstruct *pPacket, NETADDR *pAddr)
|
|||
dbg_msg("connection", "connecting online");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(State() == NET_CONNSTATE_ONLINE)
|
||||
{
|
||||
m_LastRecvTime = Now;
|
||||
AckChunks(pPacket->m_Ack);
|
||||
}
|
||||
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -292,7 +292,7 @@ int CNetConnection::Update()
|
|||
|
||||
if(State() == NET_CONNSTATE_OFFLINE || State() == NET_CONNSTATE_ERROR)
|
||||
return 0;
|
||||
|
||||
|
||||
// check for timeout
|
||||
if(State() != NET_CONNSTATE_OFFLINE &&
|
||||
State() != NET_CONNSTATE_CONNECT &&
|
||||
|
@ -322,7 +322,7 @@ int CNetConnection::Update()
|
|||
ResendChunk(pResend);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// send keep alives if nothing has happend for 250ms
|
||||
if(State() == NET_CONNSTATE_ONLINE)
|
||||
{
|
||||
|
@ -332,7 +332,7 @@ int CNetConnection::Update()
|
|||
if(NumFlushedChunks && g_Config.m_Debug)
|
||||
dbg_msg("connection", "flushed connection due to timeout. %d chunks.", NumFlushedChunks);
|
||||
}
|
||||
|
||||
|
||||
if(time_get()-m_LastSendTime > time_freq())
|
||||
SendControl(NET_CTRLMSG_KEEPALIVE, 0, 0);
|
||||
}
|
||||
|
@ -346,6 +346,6 @@ int CNetConnection::Update()
|
|||
if(time_get()-m_LastSendTime > time_freq()/2) // send a new connect/accept every 500ms
|
||||
SendControl(NET_CTRLMSG_CONNECTACCEPT, 0, 0);
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
Object->Prev = (struct CBan *)0; \
|
||||
Object->Next = First; \
|
||||
First = Object; }
|
||||
|
||||
|
||||
#define MACRO_LIST_LINK_AFTER(Object, After, Prev, Next) \
|
||||
{ Object->Prev = After; \
|
||||
Object->Next = After->Next; \
|
||||
|
@ -24,7 +24,7 @@
|
|||
if(Object->Prev) Object->Prev->Next = Object->Next; \
|
||||
else First = Object->Next; \
|
||||
Object->Next = 0; Object->Prev = 0; }
|
||||
|
||||
|
||||
#define MACRO_LIST_FIND(Start, Next, Expression) \
|
||||
{ while(Start && !(Expression)) Start = Start->Next; }
|
||||
|
||||
|
@ -32,12 +32,12 @@ bool CNetServer::Open(NETADDR BindAddr, int MaxClients, int MaxClientsPerIP, int
|
|||
{
|
||||
// zero out the whole structure
|
||||
mem_zero(this, sizeof(*this));
|
||||
|
||||
|
||||
// open socket
|
||||
m_Socket = net_udp_create(BindAddr);
|
||||
if(!m_Socket.type)
|
||||
return false;
|
||||
|
||||
|
||||
// clamp clients
|
||||
m_MaxClients = MaxClients;
|
||||
if(m_MaxClients > NET_MAX_CLIENTS)
|
||||
|
@ -46,17 +46,17 @@ bool CNetServer::Open(NETADDR BindAddr, int MaxClients, int MaxClientsPerIP, int
|
|||
m_MaxClients = 1;
|
||||
|
||||
m_MaxClientsPerIP = MaxClientsPerIP;
|
||||
|
||||
|
||||
for(int i = 0; i < NET_MAX_CLIENTS; i++)
|
||||
m_aSlots[i].m_Connection.Init(m_Socket);
|
||||
|
||||
|
||||
// setup all pointers for bans
|
||||
for(int i = 1; i < NET_SERVER_MAXBANS-1; i++)
|
||||
{
|
||||
m_BanPool[i].m_pNext = &m_BanPool[i+1];
|
||||
m_BanPool[i].m_pPrev = &m_BanPool[i-1];
|
||||
}
|
||||
|
||||
|
||||
m_BanPool[0].m_pNext = &m_BanPool[1];
|
||||
m_BanPool[NET_SERVER_MAXBANS-1].m_pPrev = &m_BanPool[NET_SERVER_MAXBANS-2];
|
||||
m_BanPool_FirstFree = &m_BanPool[0];
|
||||
|
@ -90,9 +90,9 @@ int CNetServer::Drop(int ClientID, const char *pReason)
|
|||
);*/
|
||||
if(m_pfnDelClient)
|
||||
m_pfnDelClient(ClientID, pReason, m_UserPtr);
|
||||
|
||||
|
||||
m_aSlots[ClientID].m_Connection.Disconnect(pReason);
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -101,7 +101,7 @@ int CNetServer::BanGet(int Index, CBanInfo *pInfo)
|
|||
CBan *pBan;
|
||||
for(pBan = m_BanPool_FirstUsed; pBan && Index; pBan = pBan->m_pNext, Index--)
|
||||
{}
|
||||
|
||||
|
||||
if(!pBan)
|
||||
return 0;
|
||||
*pInfo = pBan->m_Info;
|
||||
|
@ -136,15 +136,15 @@ int CNetServer::BanRemove(NETADDR Addr)
|
|||
int IpHash = (Addr.ip[0]+Addr.ip[1]+Addr.ip[2]+Addr.ip[3]+Addr.ip[4]+Addr.ip[5]+Addr.ip[6]+Addr.ip[7]+
|
||||
Addr.ip[8]+Addr.ip[9]+Addr.ip[10]+Addr.ip[11]+Addr.ip[12]+Addr.ip[13]+Addr.ip[14]+Addr.ip[15])&0xff;
|
||||
CBan *pBan = m_aBans[IpHash];
|
||||
|
||||
|
||||
MACRO_LIST_FIND(pBan, m_pHashNext, net_addr_comp(&pBan->m_Info.m_Addr, &Addr) == 0);
|
||||
|
||||
|
||||
if(pBan)
|
||||
{
|
||||
BanRemoveByObject(pBan);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -154,13 +154,13 @@ int CNetServer::BanAdd(NETADDR Addr, int Seconds, const char *pReason)
|
|||
Addr.ip[8]+Addr.ip[9]+Addr.ip[10]+Addr.ip[11]+Addr.ip[12]+Addr.ip[13]+Addr.ip[14]+Addr.ip[15])&0xff;
|
||||
int Stamp = -1;
|
||||
CBan *pBan;
|
||||
|
||||
|
||||
// remove the port
|
||||
Addr.port = 0;
|
||||
|
||||
|
||||
if(Seconds)
|
||||
Stamp = time_timestamp() + Seconds;
|
||||
|
||||
|
||||
// search to see if it already exists
|
||||
pBan = m_aBans[IpHash];
|
||||
MACRO_LIST_FIND(pBan, m_pHashNext, net_addr_comp(&pBan->m_Info.m_Addr, &Addr) == 0);
|
||||
|
@ -170,29 +170,29 @@ int CNetServer::BanAdd(NETADDR Addr, int Seconds, const char *pReason)
|
|||
pBan->m_Info.m_Expires = Stamp;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
if(!m_BanPool_FirstFree)
|
||||
return -1;
|
||||
|
||||
// fetch and clear the new ban
|
||||
pBan = m_BanPool_FirstFree;
|
||||
MACRO_LIST_UNLINK(pBan, m_BanPool_FirstFree, m_pPrev, m_pNext);
|
||||
|
||||
|
||||
// setup the ban info
|
||||
pBan->m_Info.m_Expires = Stamp;
|
||||
pBan->m_Info.m_Addr = Addr;
|
||||
str_copy(pBan->m_Info.m_Reason, pReason, sizeof(pBan->m_Info.m_Reason));
|
||||
|
||||
|
||||
// add it to the ban hash
|
||||
MACRO_LIST_LINK_FIRST(pBan, m_aBans[IpHash], m_pHashPrev, m_pHashNext);
|
||||
|
||||
|
||||
// insert it into the used list
|
||||
{
|
||||
if(m_BanPool_FirstUsed)
|
||||
{
|
||||
CBan *pInsertAfter = m_BanPool_FirstUsed;
|
||||
MACRO_LIST_FIND(pInsertAfter, m_pNext, Stamp < pInsertAfter->m_Info.m_Expires);
|
||||
|
||||
|
||||
if(pInsertAfter)
|
||||
pInsertAfter = pInsertAfter->m_pPrev;
|
||||
else
|
||||
|
@ -202,7 +202,7 @@ int CNetServer::BanAdd(NETADDR Addr, int Seconds, const char *pReason)
|
|||
while(pInsertAfter->m_pNext)
|
||||
pInsertAfter = pInsertAfter->m_pNext;
|
||||
}
|
||||
|
||||
|
||||
if(pInsertAfter)
|
||||
{
|
||||
MACRO_LIST_LINK_AFTER(pBan, pInsertAfter, m_pPrev, m_pNext);
|
||||
|
@ -222,7 +222,7 @@ int CNetServer::BanAdd(NETADDR Addr, int Seconds, const char *pReason)
|
|||
{
|
||||
char Buf[128];
|
||||
NETADDR BanAddr;
|
||||
|
||||
|
||||
int Mins = (Seconds + 59) / 60;
|
||||
if(Mins)
|
||||
{
|
||||
|
@ -233,12 +233,12 @@ int CNetServer::BanAdd(NETADDR Addr, int Seconds, const char *pReason)
|
|||
}
|
||||
else
|
||||
str_format(Buf, sizeof(Buf), "You have been banned for life (%s)", pReason);
|
||||
|
||||
|
||||
for(int i = 0; i < MaxClients(); i++)
|
||||
{
|
||||
BanAddr = m_aSlots[i].m_Connection.PeerAddress();
|
||||
BanAddr.port = 0;
|
||||
|
||||
|
||||
if(net_addr_comp(&Addr, &BanAddr) == 0)
|
||||
Drop(i, Buf);
|
||||
}
|
||||
|
@ -255,14 +255,14 @@ int CNetServer::Update()
|
|||
if(m_aSlots[i].m_Connection.State() == NET_CONNSTATE_ERROR)
|
||||
Drop(i, m_aSlots[i].m_Connection.ErrorString());
|
||||
}
|
||||
|
||||
|
||||
// remove expired bans
|
||||
while(m_BanPool_FirstUsed && m_BanPool_FirstUsed->m_Info.m_Expires < Now)
|
||||
{
|
||||
CBan *pBan = m_BanPool_FirstUsed;
|
||||
BanRemoveByObject(pBan);
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -272,22 +272,22 @@ int CNetServer::Update()
|
|||
int CNetServer::Recv(CNetChunk *pChunk)
|
||||
{
|
||||
unsigned Now = time_timestamp();
|
||||
|
||||
|
||||
while(1)
|
||||
{
|
||||
NETADDR Addr;
|
||||
|
||||
|
||||
// check for a chunk
|
||||
if(m_RecvUnpacker.FetchChunk(pChunk))
|
||||
return 1;
|
||||
|
||||
|
||||
// TODO: empty the recvinfo
|
||||
int Bytes = net_udp_recv(m_Socket, &Addr, m_RecvUnpacker.m_aBuffer, NET_MAX_PACKETSIZE);
|
||||
|
||||
// no more packets for now
|
||||
if(Bytes <= 0)
|
||||
break;
|
||||
|
||||
|
||||
if(CNetBase::UnpackPacket(m_RecvUnpacker.m_aBuffer, Bytes, &m_RecvUnpacker.m_Data) == 0)
|
||||
{
|
||||
CBan *pBan = 0;
|
||||
|
@ -296,14 +296,14 @@ int CNetServer::Recv(CNetChunk *pChunk)
|
|||
BanAddr.ip[8]+BanAddr.ip[9]+BanAddr.ip[10]+BanAddr.ip[11]+BanAddr.ip[12]+BanAddr.ip[13]+BanAddr.ip[14]+BanAddr.ip[15])&0xff;
|
||||
int Found = 0;
|
||||
BanAddr.port = 0;
|
||||
|
||||
|
||||
// search a ban
|
||||
for(pBan = m_aBans[IpHash]; pBan; pBan = pBan->m_pHashNext)
|
||||
{
|
||||
if(net_addr_comp(&pBan->m_Info.m_Addr, &BanAddr) == 0)
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
// check if we just should drop the packet
|
||||
if(pBan)
|
||||
{
|
||||
|
@ -322,7 +322,7 @@ int CNetServer::Recv(CNetChunk *pChunk)
|
|||
CNetBase::SendControlMsg(m_Socket, &Addr, 0, NET_CTRLMSG_CLOSE, BanStr, str_length(BanStr)+1);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
if(m_RecvUnpacker.m_Data.m_Flags&NET_PACKETFLAG_CONNLESS)
|
||||
{
|
||||
pChunk->m_Flags = NETSENDFLAG_CONNLESS;
|
||||
|
@ -333,12 +333,12 @@ int CNetServer::Recv(CNetChunk *pChunk)
|
|||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
{
|
||||
// TODO: check size here
|
||||
if(m_RecvUnpacker.m_Data.m_Flags&NET_PACKETFLAG_CONTROL && m_RecvUnpacker.m_Data.m_aChunkData[0] == NET_CTRLMSG_CONNECT)
|
||||
{
|
||||
Found = 0;
|
||||
|
||||
|
||||
// check if we already got this client
|
||||
for(int i = 0; i < MaxClients(); i++)
|
||||
{
|
||||
|
@ -350,7 +350,7 @@ int CNetServer::Recv(CNetChunk *pChunk)
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// client that wants to connect
|
||||
if(!Found)
|
||||
{
|
||||
|
@ -407,7 +407,7 @@ int CNetServer::Recv(CNetChunk *pChunk)
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(!Found)
|
||||
{
|
||||
const char FullMsg[] = "This server is full";
|
||||
|
@ -444,7 +444,7 @@ int CNetServer::Send(CNetChunk *pChunk)
|
|||
dbg_msg("netserver", "packet payload too big. %d. dropping packet", pChunk->m_DataSize);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
if(pChunk->m_Flags&NETSENDFLAG_CONNLESS)
|
||||
{
|
||||
// send connectionless packet
|
||||
|
@ -455,10 +455,10 @@ int CNetServer::Send(CNetChunk *pChunk)
|
|||
int Flags = 0;
|
||||
dbg_assert(pChunk->m_ClientID >= 0, "errornous client id");
|
||||
dbg_assert(pChunk->m_ClientID < MaxClients(), "errornous client id");
|
||||
|
||||
|
||||
if(pChunk->m_Flags&NETSENDFLAG_VITAL)
|
||||
Flags = NET_CHUNKFLAG_VITAL;
|
||||
|
||||
|
||||
if(m_aSlots[pChunk->m_ClientID].m_Connection.QueueChunk(Flags, pChunk->m_DataSize, pChunk->m_pData) == 0)
|
||||
{
|
||||
if(pChunk->m_Flags&NETSENDFLAG_FLUSH)
|
||||
|
|
|
@ -17,7 +17,7 @@ void CPacker::AddInt(int i)
|
|||
{
|
||||
if(m_Error)
|
||||
return;
|
||||
|
||||
|
||||
// make sure that we have space enough
|
||||
if(m_pEnd - m_pCurrent < 6)
|
||||
{
|
||||
|
@ -32,7 +32,7 @@ void CPacker::AddString(const char *pStr, int Limit)
|
|||
{
|
||||
if(m_Error)
|
||||
return;
|
||||
|
||||
|
||||
//
|
||||
if(Limit > 0)
|
||||
{
|
||||
|
@ -40,7 +40,7 @@ void CPacker::AddString(const char *pStr, int Limit)
|
|||
{
|
||||
*m_pCurrent++ = *pStr++;
|
||||
Limit--;
|
||||
|
||||
|
||||
if(m_pCurrent >= m_pEnd)
|
||||
{
|
||||
m_Error = 1;
|
||||
|
@ -69,13 +69,13 @@ void CPacker::AddRaw(const void *pData, int Size)
|
|||
{
|
||||
if(m_Error)
|
||||
return;
|
||||
|
||||
|
||||
if(m_pCurrent+Size >= m_pEnd)
|
||||
{
|
||||
m_Error = 1;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
const unsigned char *pSrc = (const unsigned char *)pData;
|
||||
while(Size)
|
||||
{
|
||||
|
@ -97,13 +97,13 @@ int CUnpacker::GetInt()
|
|||
{
|
||||
if(m_Error)
|
||||
return 0;
|
||||
|
||||
|
||||
if(m_pCurrent >= m_pEnd)
|
||||
{
|
||||
m_Error = 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int i;
|
||||
m_pCurrent = CVariableInt::Unpack(m_pCurrent, &i);
|
||||
if(m_pCurrent > m_pEnd)
|
||||
|
@ -118,7 +118,7 @@ const char *CUnpacker::GetString(int SanitizeType)
|
|||
{
|
||||
if(m_Error || m_pCurrent >= m_pEnd)
|
||||
return "";
|
||||
|
||||
|
||||
char *pPtr = (char *)m_pCurrent;
|
||||
while(*m_pCurrent) // skip the string
|
||||
{
|
||||
|
@ -130,7 +130,7 @@ const char *CUnpacker::GetString(int SanitizeType)
|
|||
}
|
||||
}
|
||||
m_pCurrent++;
|
||||
|
||||
|
||||
// sanitize all strings
|
||||
if(SanitizeType&SANITIZE)
|
||||
str_sanitize(pPtr);
|
||||
|
@ -144,7 +144,7 @@ const unsigned char *CUnpacker::GetRaw(int Size)
|
|||
const unsigned char *pPtr = m_pCurrent;
|
||||
if(m_Error)
|
||||
return 0;
|
||||
|
||||
|
||||
// check for nasty sizes
|
||||
if(Size < 0 || m_pCurrent+Size > m_pEnd)
|
||||
{
|
||||
|
|
|
@ -21,7 +21,7 @@ public:
|
|||
void AddInt(int i);
|
||||
void AddString(const char *pStr, int Limit);
|
||||
void AddRaw(const void *pData, int Size);
|
||||
|
||||
|
||||
int Size() const { return (int)(m_pCurrent-m_aBuffer); }
|
||||
const unsigned char *Data() const { return m_aBuffer; }
|
||||
bool Error() const { return m_Error; }
|
||||
|
|
|
@ -7,13 +7,13 @@
|
|||
|
||||
/*
|
||||
Connection diagram - How the initilization works.
|
||||
|
||||
|
||||
Client -> INFO -> Server
|
||||
Contains version info, name, and some other info.
|
||||
|
||||
|
||||
Client <- MAP <- Server
|
||||
Contains current map.
|
||||
|
||||
|
||||
Client -> READY -> Server
|
||||
The client has loaded the map and is ready to go,
|
||||
but the mod needs to send it's information aswell.
|
||||
|
@ -21,7 +21,7 @@
|
|||
mods_connected is called on the server.
|
||||
The client should call client_entergame when the
|
||||
mod has done it's initilization.
|
||||
|
||||
|
||||
Client -> ENTERGAME -> Server
|
||||
Tells the server to start sending snapshots.
|
||||
client_entergame and server_client_enter is called.
|
||||
|
@ -31,11 +31,11 @@
|
|||
enum
|
||||
{
|
||||
NETMSG_NULL=0,
|
||||
|
||||
|
||||
// the first thing sent by the client
|
||||
// contains the version info for the client
|
||||
NETMSG_INFO=1,
|
||||
|
||||
|
||||
// sent by server
|
||||
NETMSG_MAP_CHANGE, // sent when client should switch map
|
||||
NETMSG_MAP_DATA, // map transfer, contains a chunk of the map file
|
||||
|
@ -50,18 +50,18 @@ enum
|
|||
|
||||
NETMSG_AUTH_CHALLANGE, //
|
||||
NETMSG_AUTH_RESULT, //
|
||||
|
||||
|
||||
// sent by client
|
||||
NETMSG_READY, //
|
||||
NETMSG_ENTERGAME,
|
||||
NETMSG_INPUT, // contains the inputdata from the client
|
||||
NETMSG_RCON_CMD, //
|
||||
NETMSG_RCON_CMD, //
|
||||
NETMSG_RCON_AUTH, //
|
||||
NETMSG_REQUEST_MAP_DATA,//
|
||||
|
||||
NETMSG_AUTH_START, //
|
||||
NETMSG_AUTH_RESPONSE, //
|
||||
|
||||
|
||||
// sent by both
|
||||
NETMSG_PING,
|
||||
NETMSG_PING_REPLY,
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
#include <base/system.h>
|
||||
|
||||
#include "ringbuffer.h"
|
||||
|
||||
|
||||
CRingBufferBase::CItem *CRingBufferBase::NextBlock(CItem *pItem)
|
||||
{
|
||||
if(pItem->m_pNext)
|
||||
|
@ -27,19 +27,19 @@ CRingBufferBase::CItem *CRingBufferBase::MergeBack(CItem *pItem)
|
|||
// merge the blocks
|
||||
pItem->m_pPrev->m_Size += pItem->m_Size;
|
||||
pItem->m_pPrev->m_pNext = pItem->m_pNext;
|
||||
|
||||
|
||||
// fixup pointers
|
||||
if(pItem->m_pNext)
|
||||
pItem->m_pNext->m_pPrev = pItem->m_pPrev;
|
||||
else
|
||||
m_pLast = pItem->m_pPrev;
|
||||
|
||||
|
||||
if(pItem == m_pProduce)
|
||||
m_pProduce = pItem->m_pPrev;
|
||||
|
||||
|
||||
if(pItem == m_pConsume)
|
||||
m_pConsume = pItem->m_pPrev;
|
||||
|
||||
|
||||
// return the current block
|
||||
return pItem->m_pPrev;
|
||||
}
|
||||
|
@ -54,8 +54,8 @@ void CRingBufferBase::Init(void *pMemory, int Size, int Flags)
|
|||
m_pLast = m_pFirst;
|
||||
m_pProduce = m_pFirst;
|
||||
m_pConsume = m_pFirst;
|
||||
m_Flags = Flags;
|
||||
|
||||
m_Flags = Flags;
|
||||
|
||||
}
|
||||
|
||||
void *CRingBufferBase::Allocate(int Size)
|
||||
|
@ -67,7 +67,7 @@ void *CRingBufferBase::Allocate(int Size)
|
|||
if(WantedSize > m_Size)
|
||||
return 0;
|
||||
|
||||
while(1)
|
||||
while(1)
|
||||
{
|
||||
// check for space
|
||||
if(m_pProduce->m_Free)
|
||||
|
@ -81,7 +81,7 @@ void *CRingBufferBase::Allocate(int Size)
|
|||
pBlock = m_pFirst;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(pBlock)
|
||||
break;
|
||||
else
|
||||
|
@ -96,9 +96,9 @@ void *CRingBufferBase::Allocate(int Size)
|
|||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// okey, we have our block
|
||||
|
||||
|
||||
// split the block if needed
|
||||
if(pBlock->m_Size > WantedSize+(int)sizeof(CItem))
|
||||
{
|
||||
|
@ -108,19 +108,19 @@ void *CRingBufferBase::Allocate(int Size)
|
|||
if(pNewItem->m_pNext)
|
||||
pNewItem->m_pNext->m_pPrev = pNewItem;
|
||||
pBlock->m_pNext = pNewItem;
|
||||
|
||||
|
||||
pNewItem->m_Free = 1;
|
||||
pNewItem->m_Size = pBlock->m_Size - WantedSize;
|
||||
pBlock->m_Size = WantedSize;
|
||||
|
||||
|
||||
if(!pNewItem->m_pNext)
|
||||
m_pLast = pNewItem;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// set next block
|
||||
m_pProduce = NextBlock(pBlock);
|
||||
|
||||
|
||||
// set as used and return the item pointer
|
||||
pBlock->m_Free = 0;
|
||||
return (void *)(pBlock+1);
|
||||
|
@ -130,13 +130,13 @@ int CRingBufferBase::PopFirst()
|
|||
{
|
||||
if(m_pConsume->m_Free)
|
||||
return 0;
|
||||
|
||||
|
||||
// set the free flag
|
||||
m_pConsume->m_Free = 1;
|
||||
|
||||
|
||||
// previous block is also free, merge them
|
||||
m_pConsume = MergeBack(m_pConsume);
|
||||
|
||||
|
||||
// advance the consume pointer
|
||||
m_pConsume = NextBlock(m_pConsume);
|
||||
while(m_pConsume->m_Free && m_pConsume != m_pProduce)
|
||||
|
@ -144,7 +144,7 @@ int CRingBufferBase::PopFirst()
|
|||
m_pConsume = MergeBack(m_pConsume);
|
||||
m_pConsume = NextBlock(m_pConsume);
|
||||
}
|
||||
|
||||
|
||||
// in the case that we have catched up with the produce pointer
|
||||
// we might stand on a free block so merge em
|
||||
MergeBack(m_pConsume);
|
||||
|
@ -155,7 +155,7 @@ int CRingBufferBase::PopFirst()
|
|||
void *CRingBufferBase::Prev(void *pCurrent)
|
||||
{
|
||||
CItem *pItem = ((CItem *)pCurrent) - 1;
|
||||
|
||||
|
||||
while(1)
|
||||
{
|
||||
pItem = PrevBlock(pItem);
|
||||
|
@ -169,7 +169,7 @@ void *CRingBufferBase::Prev(void *pCurrent)
|
|||
void *CRingBufferBase::Next(void *pCurrent)
|
||||
{
|
||||
CItem *pItem = ((CItem *)pCurrent) - 1;
|
||||
|
||||
|
||||
while(1)
|
||||
{
|
||||
pItem = NextBlock(pItem);
|
||||
|
|
|
@ -15,28 +15,28 @@ class CRingBufferBase
|
|||
int m_Free;
|
||||
int m_Size;
|
||||
};
|
||||
|
||||
|
||||
CItem *m_pProduce;
|
||||
CItem *m_pConsume;
|
||||
|
||||
|
||||
CItem *m_pFirst;
|
||||
CItem *m_pLast;
|
||||
|
||||
|
||||
void *m_pMemory;
|
||||
int m_Size;
|
||||
int m_Flags;
|
||||
|
||||
|
||||
CItem *NextBlock(CItem *pItem);
|
||||
CItem *PrevBlock(CItem *pItem);
|
||||
CItem *MergeBack(CItem *pItem);
|
||||
protected:
|
||||
void *Allocate(int Size);
|
||||
|
||||
|
||||
void *Prev(void *pCurrent);
|
||||
void *Next(void *pCurrent);
|
||||
void *First();
|
||||
void *Last();
|
||||
|
||||
|
||||
void Init(void *pMemory, int Size, int Flags);
|
||||
int PopFirst();
|
||||
public:
|
||||
|
@ -53,9 +53,9 @@ class TStaticRingBuffer : public CRingBufferBase
|
|||
unsigned char m_aBuffer[TSIZE];
|
||||
public:
|
||||
TStaticRingBuffer() { Init(); }
|
||||
|
||||
|
||||
void Init() { CRingBufferBase::Init(m_aBuffer, TSIZE, TFLAGS); }
|
||||
|
||||
|
||||
T *Allocate(int Size) { return (T*)CRingBufferBase::Allocate(Size); }
|
||||
int PopFirst() { return CRingBufferBase::PopFirst(); }
|
||||
|
||||
|
|
|
@ -12,31 +12,31 @@ CSnapshotItem *CSnapshot::GetItem(int Index)
|
|||
|
||||
int CSnapshot::GetItemSize(int Index)
|
||||
{
|
||||
if(Index == m_NumItems-1)
|
||||
return (m_DataSize - Offsets()[Index]) - sizeof(CSnapshotItem);
|
||||
return (Offsets()[Index+1] - Offsets()[Index]) - sizeof(CSnapshotItem);
|
||||
if(Index == m_NumItems-1)
|
||||
return (m_DataSize - Offsets()[Index]) - sizeof(CSnapshotItem);
|
||||
return (Offsets()[Index+1] - Offsets()[Index]) - sizeof(CSnapshotItem);
|
||||
}
|
||||
|
||||
int CSnapshot::GetItemIndex(int Key)
|
||||
{
|
||||
// TODO: OPT: this should not be a linear search. very bad
|
||||
for(int i = 0; i < m_NumItems; i++)
|
||||
{
|
||||
if(GetItem(i)->Key() == Key)
|
||||
return i;
|
||||
}
|
||||
return -1;
|
||||
// TODO: OPT: this should not be a linear search. very bad
|
||||
for(int i = 0; i < m_NumItems; i++)
|
||||
{
|
||||
if(GetItem(i)->Key() == Key)
|
||||
return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int CSnapshot::Crc()
|
||||
{
|
||||
int Crc = 0;
|
||||
|
||||
|
||||
for(int i = 0; i < m_NumItems; i++)
|
||||
{
|
||||
CSnapshotItem *pItem = GetItem(i);
|
||||
int Size = GetItemSize(i);
|
||||
|
||||
|
||||
for(int b = 0; b < Size/4; b++)
|
||||
Crc += pItem->Data()[b];
|
||||
}
|
||||
|
@ -75,7 +75,7 @@ static void GenerateHash(CItemList *pHashlist, CSnapshot *pSnapshot)
|
|||
{
|
||||
for(int i = 0; i < HASHLIST_SIZE; i++)
|
||||
pHashlist[i].m_Num = 0;
|
||||
|
||||
|
||||
for(int i = 0; i < pSnapshot->NumItems(); i++)
|
||||
{
|
||||
int Key = pSnapshot->GetItem(i)->Key();
|
||||
|
@ -97,7 +97,7 @@ static int GetItemIndexHashed(int Key, const CItemList *pHashlist)
|
|||
if(pHashlist[HashID].m_aKeys[i] == Key)
|
||||
return pHashlist[HashID].m_aIndex[i];
|
||||
}
|
||||
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -113,7 +113,7 @@ static int DiffItem(int *pPast, int *pCurrent, int *pOut, int Size)
|
|||
pCurrent++;
|
||||
Size--;
|
||||
}
|
||||
|
||||
|
||||
return Needed;
|
||||
}
|
||||
|
||||
|
@ -122,16 +122,16 @@ void CSnapshotDelta::UndiffItem(int *pPast, int *pDiff, int *pOut, int Size)
|
|||
while(Size)
|
||||
{
|
||||
*pOut = *pPast+*pDiff;
|
||||
|
||||
|
||||
if(*pDiff == 0)
|
||||
m_aSnapshotDataRate[m_SnapshotCurrent] += 1;
|
||||
else
|
||||
{
|
||||
unsigned char aBuf[16];
|
||||
unsigned char *pEnd = CVariableInt::Pack(aBuf, *pDiff);
|
||||
unsigned char *pEnd = CVariableInt::Pack(aBuf, *pDiff);
|
||||
m_aSnapshotDataRate[m_SnapshotCurrent] += (int)(pEnd - (unsigned char*)aBuf) * 8;
|
||||
}
|
||||
|
||||
|
||||
pOut++;
|
||||
pPast++;
|
||||
pDiff++;
|
||||
|
@ -169,11 +169,11 @@ int CSnapshotDelta::CreateDelta(CSnapshot *pFrom, CSnapshot *pTo, void *pDstData
|
|||
CSnapshotItem *pPastItem;
|
||||
int Count = 0;
|
||||
int SizeCount = 0;
|
||||
|
||||
|
||||
pDelta->m_NumDeletedItems = 0;
|
||||
pDelta->m_NumUpdateItems = 0;
|
||||
pDelta->m_NumTempItems = 0;
|
||||
|
||||
|
||||
CItemList Hashlist[HASHLIST_SIZE];
|
||||
GenerateHash(Hashlist, pTo);
|
||||
|
||||
|
@ -189,7 +189,7 @@ int CSnapshotDelta::CreateDelta(CSnapshot *pFrom, CSnapshot *pTo, void *pDstData
|
|||
pData++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
GenerateHash(Hashlist, pFrom);
|
||||
int aPastIndecies[1024];
|
||||
|
||||
|
@ -197,29 +197,29 @@ int CSnapshotDelta::CreateDelta(CSnapshot *pFrom, CSnapshot *pTo, void *pDstData
|
|||
// we do this as a separate pass because it helps the cache
|
||||
for(i = 0; i < pTo->NumItems(); i++)
|
||||
{
|
||||
pCurItem = pTo->GetItem(i); // O(1) .. O(n)
|
||||
pCurItem = pTo->GetItem(i); // O(1) .. O(n)
|
||||
aPastIndecies[i] = GetItemIndexHashed(pCurItem->Key(), Hashlist); // O(n) .. O(n^n)
|
||||
}
|
||||
|
||||
|
||||
for(i = 0; i < pTo->NumItems(); i++)
|
||||
{
|
||||
// do delta
|
||||
ItemSize = pTo->GetItemSize(i); // O(1) .. O(n)
|
||||
pCurItem = pTo->GetItem(i); // O(1) .. O(n)
|
||||
pCurItem = pTo->GetItem(i); // O(1) .. O(n)
|
||||
PastIndex = aPastIndecies[i];
|
||||
|
||||
|
||||
if(PastIndex != -1)
|
||||
{
|
||||
int *pItemDataDst = pData+3;
|
||||
|
||||
|
||||
pPastItem = pFrom->GetItem(PastIndex);
|
||||
|
||||
|
||||
if(m_aItemSizes[pCurItem->Type()])
|
||||
pItemDataDst = pData+2;
|
||||
|
||||
|
||||
if(DiffItem((int*)pPastItem->Data(), (int*)pCurItem->Data(), pItemDataDst, ItemSize/4))
|
||||
{
|
||||
|
||||
|
||||
*pData++ = pCurItem->Type();
|
||||
*pData++ = pCurItem->ID();
|
||||
if(!m_aItemSizes[pCurItem->Type()])
|
||||
|
@ -234,7 +234,7 @@ int CSnapshotDelta::CreateDelta(CSnapshot *pFrom, CSnapshot *pTo, void *pDstData
|
|||
*pData++ = pCurItem->ID();
|
||||
if(!m_aItemSizes[pCurItem->Type()])
|
||||
*pData++ = ItemSize/4;
|
||||
|
||||
|
||||
mem_copy(pData, pCurItem->Data(), ItemSize);
|
||||
SizeCount += ItemSize;
|
||||
pData += ItemSize/4;
|
||||
|
@ -242,7 +242,7 @@ int CSnapshotDelta::CreateDelta(CSnapshot *pFrom, CSnapshot *pTo, void *pDstData
|
|||
Count++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(0)
|
||||
{
|
||||
dbg_msg("snapshot", "%d %d %d",
|
||||
|
@ -253,7 +253,7 @@ int CSnapshotDelta::CreateDelta(CSnapshot *pFrom, CSnapshot *pTo, void *pDstData
|
|||
|
||||
/*
|
||||
// TODO: pack temp stuff
|
||||
|
||||
|
||||
// finish
|
||||
//mem_copy(pDelta->offsets, deleted, pDelta->num_deleted_items*sizeof(int));
|
||||
//mem_copy(&(pDelta->offsets[pDelta->num_deleted_items]), update, pDelta->num_update_items*sizeof(int));
|
||||
|
@ -261,10 +261,10 @@ int CSnapshotDelta::CreateDelta(CSnapshot *pFrom, CSnapshot *pTo, void *pDstData
|
|||
//mem_copy(pDelta->data_start(), data, data_size);
|
||||
//pDelta->data_size = data_size;
|
||||
* */
|
||||
|
||||
|
||||
if(!pDelta->m_NumDeletedItems && !pDelta->m_NumUpdateItems && !pDelta->m_NumTempItems)
|
||||
return 0;
|
||||
|
||||
|
||||
return (int)((char*)pData-(char*)pDstData);
|
||||
}
|
||||
|
||||
|
@ -281,16 +281,16 @@ int CSnapshotDelta::UnpackDelta(CSnapshot *pFrom, CSnapshot *pTo, void *pSrcData
|
|||
CData *pDelta = (CData *)pSrcData;
|
||||
int *pData = (int *)pDelta->m_pData;
|
||||
int *pEnd = (int *)(((char *)pSrcData + DataSize));
|
||||
|
||||
|
||||
CSnapshotItem *pFromItem;
|
||||
int Keep, ItemSize;
|
||||
int *pDeleted;
|
||||
int ID, Type, Key;
|
||||
int FromIndex;
|
||||
int *pNewData;
|
||||
|
||||
|
||||
Builder.Init();
|
||||
|
||||
|
||||
// unpack deleted stuff
|
||||
pDeleted = pData;
|
||||
pData += pDelta->m_NumDeletedItems;
|
||||
|
@ -302,7 +302,7 @@ int CSnapshotDelta::UnpackDelta(CSnapshot *pFrom, CSnapshot *pTo, void *pSrcData
|
|||
{
|
||||
// dbg_assert(0, "fail!");
|
||||
pFromItem = pFrom->GetItem(i);
|
||||
ItemSize = pFrom->GetItemSize(i);
|
||||
ItemSize = pFrom->GetItemSize(i);
|
||||
Keep = 1;
|
||||
for(int d = 0; d < pDelta->m_NumDeletedItems; d++)
|
||||
{
|
||||
|
@ -312,7 +312,7 @@ int CSnapshotDelta::UnpackDelta(CSnapshot *pFrom, CSnapshot *pTo, void *pSrcData
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(Keep)
|
||||
{
|
||||
// keep it
|
||||
|
@ -321,13 +321,13 @@ int CSnapshotDelta::UnpackDelta(CSnapshot *pFrom, CSnapshot *pTo, void *pSrcData
|
|||
pFromItem->Data(), ItemSize);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// unpack updated stuff
|
||||
for(int i = 0; i < pDelta->m_NumUpdateItems; i++)
|
||||
{
|
||||
if(pData+2 > pEnd)
|
||||
return -1;
|
||||
|
||||
|
||||
Type = *pData++;
|
||||
ID = *pData++;
|
||||
if(m_aItemSizes[Type])
|
||||
|
@ -339,18 +339,18 @@ int CSnapshotDelta::UnpackDelta(CSnapshot *pFrom, CSnapshot *pTo, void *pSrcData
|
|||
ItemSize = (*pData++) * 4;
|
||||
}
|
||||
m_SnapshotCurrent = Type;
|
||||
|
||||
|
||||
if(RangeCheck(pEnd, pData, ItemSize) || ItemSize < 0) return -3;
|
||||
|
||||
|
||||
Key = (Type<<16)|ID;
|
||||
|
||||
|
||||
// create the item if needed
|
||||
pNewData = Builder.GetItemData(Key);
|
||||
if(!pNewData)
|
||||
pNewData = (int *)Builder.NewItem(Key>>16, Key&0xffff, ItemSize);
|
||||
|
||||
//if(range_check(pEnd, pNewData, ItemSize)) return -4;
|
||||
|
||||
|
||||
FromIndex = pFrom->GetItemIndex(Key);
|
||||
if(FromIndex != -1)
|
||||
{
|
||||
|
@ -364,10 +364,10 @@ int CSnapshotDelta::UnpackDelta(CSnapshot *pFrom, CSnapshot *pTo, void *pSrcData
|
|||
m_aSnapshotDataRate[m_SnapshotCurrent] += ItemSize*8;
|
||||
m_aSnapshotDataUpdates[m_SnapshotCurrent]++;
|
||||
}
|
||||
|
||||
|
||||
pData += ItemSize/4;
|
||||
}
|
||||
|
||||
|
||||
// finish up
|
||||
return Builder.Finish(pTo);
|
||||
}
|
||||
|
@ -402,24 +402,24 @@ void CSnapshotStorage::PurgeUntil(int Tick)
|
|||
{
|
||||
CHolder *pHolder = m_pFirst;
|
||||
CHolder *pNext;
|
||||
|
||||
|
||||
while(pHolder)
|
||||
{
|
||||
pNext = pHolder->m_pNext;
|
||||
if(pHolder->m_Tick >= Tick)
|
||||
return; // no more to remove
|
||||
mem_free(pHolder);
|
||||
|
||||
|
||||
// did we come to the end of the list?
|
||||
if (!pNext)
|
||||
break;
|
||||
if (!pNext)
|
||||
break;
|
||||
|
||||
m_pFirst = pNext;
|
||||
pNext->m_pPrev = 0x0;
|
||||
|
||||
|
||||
pHolder = pNext;
|
||||
}
|
||||
|
||||
|
||||
// no more snapshots in storage
|
||||
m_pFirst = 0;
|
||||
m_pLast = 0;
|
||||
|
@ -429,12 +429,12 @@ void CSnapshotStorage::Add(int Tick, int64 Tagtime, int DataSize, void *pData, i
|
|||
{
|
||||
// allocate memory for holder + snapshot_data
|
||||
int TotalSize = sizeof(CHolder)+DataSize;
|
||||
|
||||
|
||||
if(CreateAlt)
|
||||
TotalSize += DataSize;
|
||||
|
||||
|
||||
CHolder *pHolder = (CHolder *)mem_alloc(TotalSize, 1);
|
||||
|
||||
|
||||
// set data
|
||||
pHolder->m_Tick = Tick;
|
||||
pHolder->m_Tagtime = Tagtime;
|
||||
|
@ -449,8 +449,8 @@ void CSnapshotStorage::Add(int Tick, int64 Tagtime, int DataSize, void *pData, i
|
|||
}
|
||||
else
|
||||
pHolder->m_pAltSnap = 0;
|
||||
|
||||
|
||||
|
||||
|
||||
// link
|
||||
pHolder->m_pNext = 0;
|
||||
pHolder->m_pPrev = m_pLast;
|
||||
|
@ -464,7 +464,7 @@ void CSnapshotStorage::Add(int Tick, int64 Tagtime, int DataSize, void *pData, i
|
|||
int CSnapshotStorage::Get(int Tick, int64 *pTagtime, CSnapshot **ppData, CSnapshot **ppAltData)
|
||||
{
|
||||
CHolder *pHolder = m_pFirst;
|
||||
|
||||
|
||||
while(pHolder)
|
||||
{
|
||||
if(pHolder->m_Tick == Tick)
|
||||
|
@ -477,10 +477,10 @@ int CSnapshotStorage::Get(int Tick, int64 *pTagtime, CSnapshot **ppData, CSnapsh
|
|||
*ppData = pHolder->m_pAltSnap;
|
||||
return pHolder->m_SnapSize;
|
||||
}
|
||||
|
||||
|
||||
pHolder = pHolder->m_pNext;
|
||||
}
|
||||
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -492,7 +492,7 @@ void CSnapshotBuilder::Init()
|
|||
m_NumItems = 0;
|
||||
}
|
||||
|
||||
CSnapshotItem *CSnapshotBuilder::GetItem(int Index)
|
||||
CSnapshotItem *CSnapshotBuilder::GetItem(int Index)
|
||||
{
|
||||
return (CSnapshotItem *)&(m_aData[m_aOffsets[Index]]);
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ class CSnapshotItem
|
|||
{
|
||||
public:
|
||||
int m_TypeAndID;
|
||||
|
||||
|
||||
int *Data() { return (int *)(this+1); }
|
||||
int Type() { return m_TypeAndID>>16; }
|
||||
int ID() { return m_TypeAndID&0xffff; }
|
||||
|
@ -90,15 +90,15 @@ public:
|
|||
public:
|
||||
CHolder *m_pPrev;
|
||||
CHolder *m_pNext;
|
||||
|
||||
|
||||
int64 m_Tagtime;
|
||||
int m_Tick;
|
||||
|
||||
|
||||
int m_SnapSize;
|
||||
CSnapshot *m_pSnap;
|
||||
CSnapshot *m_pAltSnap;
|
||||
};
|
||||
|
||||
|
||||
|
||||
CHolder *m_pFirst;
|
||||
CHolder *m_pLast;
|
||||
|
@ -125,12 +125,12 @@ class CSnapshotBuilder
|
|||
|
||||
public:
|
||||
void Init();
|
||||
|
||||
|
||||
void *NewItem(int Type, int ID, int Size);
|
||||
|
||||
|
||||
CSnapshotItem *GetItem(int Index);
|
||||
int *GetItemData(int Key);
|
||||
|
||||
|
||||
int Finish(void *Snapdata);
|
||||
};
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@ public:
|
|||
char m_aDatadir[MAX_PATH_LENGTH];
|
||||
char m_aUserdir[MAX_PATH_LENGTH];
|
||||
char m_aCurrentdir[MAX_PATH_LENGTH];
|
||||
|
||||
|
||||
CStorage()
|
||||
{
|
||||
mem_zero(m_aaStoragePaths, sizeof(m_aaStoragePaths));
|
||||
|
@ -29,7 +29,7 @@ public:
|
|||
m_aDatadir[0] = 0;
|
||||
m_aUserdir[0] = 0;
|
||||
}
|
||||
|
||||
|
||||
int Init(const char *pApplicationName, int NumArgs, const char **ppArguments)
|
||||
{
|
||||
// get userdir
|
||||
|
@ -86,7 +86,7 @@ public:
|
|||
str_append(aBuffer, "/storage.cfg", sizeof(aBuffer));
|
||||
File = io_open(aBuffer, IOFLAG_READ);
|
||||
}
|
||||
|
||||
|
||||
if(Pos >= MAX_PATH_LENGTH || !File)
|
||||
{
|
||||
dbg_msg("storage", "couldn't open storage.cfg");
|
||||
|
@ -152,7 +152,7 @@ public:
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void FindDatadir(const char *pArgv0)
|
||||
{
|
||||
// 1) use data-dir in PWD if present
|
||||
|
@ -161,35 +161,35 @@ public:
|
|||
str_copy(m_aDatadir, "data", sizeof(m_aDatadir));
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// 2) use compiled-in data-dir if present
|
||||
if(fs_is_dir(DATA_DIR "/mapres"))
|
||||
{
|
||||
str_copy(m_aDatadir, DATA_DIR, sizeof(m_aDatadir));
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// 3) check for usable path in argv[0]
|
||||
{
|
||||
unsigned int Pos = ~0U;
|
||||
for(unsigned i = 0; pArgv0[i]; i++)
|
||||
if(pArgv0[i] == '/' || pArgv0[i] == '\\')
|
||||
Pos = i;
|
||||
|
||||
|
||||
if(Pos < MAX_PATH_LENGTH)
|
||||
{
|
||||
char aBaseDir[MAX_PATH_LENGTH];
|
||||
str_copy(aBaseDir, pArgv0, Pos+1);
|
||||
str_format(m_aDatadir, sizeof(m_aDatadir), "%s/data", aBaseDir);
|
||||
str_append(aBaseDir, "/data/mapres", sizeof(aBaseDir));
|
||||
|
||||
|
||||
if(fs_is_dir(aBaseDir))
|
||||
return;
|
||||
else
|
||||
m_aDatadir[0] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#if defined(CONF_FAMILY_UNIX)
|
||||
// 4) check for all default locations
|
||||
{
|
||||
|
@ -201,7 +201,7 @@ public:
|
|||
"/opt/teeworlds/data"
|
||||
};
|
||||
const int DirsCount = sizeof(aDirs) / sizeof(aDirs[0]);
|
||||
|
||||
|
||||
int i;
|
||||
for (i = 0; i < DirsCount; i++)
|
||||
{
|
||||
|
@ -215,7 +215,7 @@ public:
|
|||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
// no data-dir found
|
||||
dbg_msg("storage", "warning no data directory found");
|
||||
}
|
||||
|
@ -241,7 +241,7 @@ public:
|
|||
str_format(pBuffer, BufferSize, "%s%s%s", m_aaStoragePaths[Type], !m_aaStoragePaths[Type][0] ? "" : "/", pDir);
|
||||
return pBuffer;
|
||||
}
|
||||
|
||||
|
||||
virtual IOHANDLE OpenFile(const char *pFilename, int Flags, int Type, char *pBuffer = 0, int BufferSize = 0)
|
||||
{
|
||||
char aBuffer[MAX_PATH_LENGTH];
|
||||
|
@ -250,7 +250,7 @@ public:
|
|||
pBuffer = aBuffer;
|
||||
BufferSize = sizeof(aBuffer);
|
||||
}
|
||||
|
||||
|
||||
if(Flags&IOFLAG_WRITE)
|
||||
{
|
||||
return io_open(GetPath(TYPE_SAVE, pFilename, pBuffer, BufferSize), Flags);
|
||||
|
@ -277,11 +277,11 @@ public:
|
|||
return Handle;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
pBuffer[0] = 0;
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
struct CFindCBData
|
||||
{
|
||||
CStorage *pStorage;
|
||||
|
@ -322,7 +322,7 @@ public:
|
|||
{
|
||||
if(BufferSize < 1)
|
||||
return false;
|
||||
|
||||
|
||||
pBuffer[0] = 0;
|
||||
char aBuf[MAX_PATH_LENGTH];
|
||||
CFindCBData Data;
|
||||
|
|
|
@ -21,9 +21,9 @@ public:
|
|||
virtual void SetChannel(int ChannelID, float Volume, float Panning) = 0;
|
||||
virtual void SetListenerPos(float x, float y) = 0;
|
||||
|
||||
virtual int PlayAt(int ChannelID, int SoundID, int Flags, float x, float y) = 0;
|
||||
virtual int Play(int ChannelID, int SoundID, int Flags) = 0;
|
||||
virtual void Stop(int VoiceID) = 0;
|
||||
virtual int PlayAt(int ChannelID, int SampleID, int Flags, float x, float y) = 0;
|
||||
virtual int Play(int ChannelID, int SampleID, int Flags) = 0;
|
||||
virtual void Stop(int SampleID) = 0;
|
||||
virtual void StopAll() = 0;
|
||||
};
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@ public:
|
|||
TYPE_SAVE = 0,
|
||||
TYPE_ALL = -1
|
||||
};
|
||||
|
||||
|
||||
virtual void ListDirectory(int Type, const char *pPath, FS_LISTDIR_CALLBACK pfnCallback, void *pUser) = 0;
|
||||
virtual IOHANDLE OpenFile(const char *pFilename, int Flags, int Type, char *pBuffer = 0, int BufferSize = 0) = 0;
|
||||
virtual bool FindFile(const char *pFilename, const char *pPath, int Type, char *pBuffer, int BufferSize) = 0;
|
||||
|
|
|
@ -20,12 +20,12 @@ public:
|
|||
int m_LineCount;
|
||||
int m_CharCount;
|
||||
int m_MaxLines;
|
||||
|
||||
|
||||
float m_StartX;
|
||||
float m_StartY;
|
||||
float m_LineWidth;
|
||||
float m_X, m_Y;
|
||||
|
||||
|
||||
CFont *m_pFont;
|
||||
float m_FontSize;
|
||||
};
|
||||
|
@ -35,15 +35,15 @@ class ITextRender : public IInterface
|
|||
MACRO_INTERFACE("textrender", 0)
|
||||
public:
|
||||
virtual void SetCursor(CTextCursor *pCursor, float x, float y, float FontSize, int Flags) = 0;
|
||||
|
||||
|
||||
virtual CFont *LoadFont(const char *pFilename) = 0;
|
||||
virtual void DestroyFont(CFont *pFont) = 0;
|
||||
|
||||
|
||||
virtual void SetDefaultFont(CFont *pFont) = 0;
|
||||
|
||||
//
|
||||
virtual void TextEx(CTextCursor *pCursor, const char *pText, int Length) = 0;
|
||||
|
||||
|
||||
// old foolish interface
|
||||
virtual void TextColor(float r, float g, float b, float a) = 0;
|
||||
virtual void TextOutlineColor(float r, float g, float b, float a) = 0;
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue