Navigation Menu

Skip to content

Commit

Permalink
Refactor|libdeng2: Replaced /config with /modules
Browse files Browse the repository at this point in the history
There is no need to have a folder just for config scripts. Instead,
the /modules folder is now used for storing all scripts.

Added the recutil.de module: Record manipulation utilities.
  • Loading branch information
skyjake committed Dec 3, 2012
1 parent 273a5a8 commit 172548d
Show file tree
Hide file tree
Showing 9 changed files with 170 additions and 97 deletions.
4 changes: 3 additions & 1 deletion distrib/win32/setup.iss.template
Expand Up @@ -65,6 +65,7 @@ Type: files; Name: "{app}\bin\dpwadmapconverter.dll"
Type: files; Name: "{app}\data\jdoom\jDoom.pk3"
Type: files; Name: "{app}\data\jheretic\jHeretic.pk3"
Type: files; Name: "{app}\data\jhexen\jHexen.pk3"
Type: filesandordirs; Name: "{app}\config"

[Files]
; NOTE: Don't use "Flags: ignoreversion" on any shared system files
Expand Down Expand Up @@ -120,7 +121,8 @@ Source: "doc\LICENSE"; DestDir: "{app}\doc"; Components: Engine
Source: "doc\readme.txt"; DestDir: "{app}\doc"; Components: Engine

; Resources
Source: "config\deng.de"; DestDir: "{app}\config"; Components: Engine
Source: "modules\Config.de"; DestDir: "{app}\modules"; Components: Engine
Source: "modules\recutil.de"; DestDir: "{app}\modules"; Components: Engine
Source: "data\doomsday.pk3"; DestDir: "{app}\data"; Components: Engine
Source: "data\graphics\background.pcx"; DestDir: "{app}\data\graphics"; Components: Engine
Source: "data\graphics\loading1.png"; DestDir: "{app}\data\graphics"; Components: Engine
Expand Down
2 changes: 1 addition & 1 deletion doomsday/config.pri
Expand Up @@ -47,7 +47,7 @@ DENG_WIN_INCLUDE_DIR = $$DENG_INCLUDE_DIR/windows
# Binaries and generated files are placed here.
DENG_WIN_PRODUCTS_DIR = $$PWD/../distrib/products

DENG_CONFIG_DIR = $$PWD/libdeng2/config
DENG_MODULES_DIR = $$PWD/libdeng2/modules

# Versions -------------------------------------------------------------------

Expand Down
12 changes: 7 additions & 5 deletions doomsday/engine/engine.pro
Expand Up @@ -648,7 +648,9 @@ OTHER_FILES += \

data.files = $$OUT_PWD/../doomsday.pk3

cfg.files = $$DENG_CONFIG_DIR/deng.de
mod.files = \
$$DENG_MODULES_DIR/Config.de \
$$DENG_MODULES_DIR/recutil.de

startupdata.files = \
data/cphelp.txt
Expand Down Expand Up @@ -680,13 +682,13 @@ macx {
res/macx/English.lproj \
res/macx/deng.icns

cfg.path = $${res.path}/config
data.path = $${res.path}
mod.path = $${res.path}/modules
startupdata.path = $${res.path}/data
startupfonts.path = $${res.path}/data/fonts
startupgfx.path = $${res.path}/data/graphics

QMAKE_BUNDLE_DATA += cfg res data startupfonts startupdata startupgfx
QMAKE_BUNDLE_DATA += mod res data startupfonts startupdata startupgfx

QMAKE_INFO_PLIST = ../build/mac/Info.plist

Expand Down Expand Up @@ -724,14 +726,14 @@ macx {

!macx {
# Common (non-Mac) parts of the installation.
INSTALLS += target data startupdata startupgfx startupfonts cfg
INSTALLS += target data startupdata startupgfx startupfonts mod

target.path = $$DENG_BIN_DIR
data.path = $$DENG_DATA_DIR
startupdata.path = $$DENG_DATA_DIR
startupgfx.path = $$DENG_DATA_DIR/graphics
startupfonts.path = $$DENG_DATA_DIR/fonts
cfg.path = $$DENG_BASE_DIR/config
mod.path = $$DENG_BASE_DIR/modules

win32 {
# Windows-specific installation.
Expand Down
75 changes: 0 additions & 75 deletions doomsday/libdeng2/config/deng.de

This file was deleted.

3 changes: 2 additions & 1 deletion doomsday/libdeng2/libdeng2.pro
Expand Up @@ -108,7 +108,8 @@ SOURCES += \
src/core/unixinfo.cpp

OTHER_FILES += \
config/deng.de
modules/Config.de \
modules/recutil.de

# Installation ---------------------------------------------------------------

Expand Down
98 changes: 98 additions & 0 deletions doomsday/libdeng2/modules/Config.de
@@ -0,0 +1,98 @@
# The Doomsday Engine Project -- libdeng2
#
# Copyright (c) 2012 Jaakko Keränen <jaakko.keranen@iki.fi>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/>.

#----------------------------------------------------------------------------
# MAIN CONFIGURATION FOR LIBDENG2
#
# This module is the special Config namespace, reserved for the engine's
# configuration variables and routines. The namespace is stored persistently
# (persist.pack/modules/Config). The script is executed only when it has
# been updated or when __version__ has changed.

# Cleanup: this is a persistent namespace so old stuff may be hanging around.
for name in ['setDefaults', 'updateWithDefaults']
if name in locals(): del locals()[name]
end
del name

def setDefaults(d = None)
# Applies the default configuration.
# - d: Record where to set the values. If not specified, the
# Config namespace is used.
if d == None
print "Defaults are set in the main Config namespace."
import Config
d = Config
end

d.importPath = ['', '/modules']

# The default audio and video subsystems.
d.video = 'opengl'
d.audio = 'fmod'

# Window manager defaults.
record d.window
record d.window.main

d.window.fsaa = True

d.window.main.rect = [0, 0, 640, 480]
d.window.main.colorDepth = 32
d.window.main.center = True
d.window.main.maximize = False
d.window.main.fullscreen = True

# Log parameters.
record d.log

# Log message levels.
const d.log.TRACE = 0
const d.log.DEBUG = 1
const d.log.VERBOSE = 2
const d.log.MESSAGE = 3
const d.log.INFO = 4
const d.log.WARNING = 5
const d.log.ERROR = 6
const d.log.CRITICAL = 7

d.log.file = '/home/doomsday.out'
d.log.level = d.log.MESSAGE
d.log.bufferSize = 1000
end

def updateWithDefaults()
record defaults
setDefaults(defaults)
# Anything that is not already in Config should be added.
import recutil, Config
recutil.copyMissingMembers(defaults, Config)
end

updateWithDefaults()

# Check the previous version and decide what to do.
if '__oldversion__' in locals()
if __version__[3] > __oldversion__[3]
# Current build number is newer.
print 'Detected new build:', __oldversion__[3], '=>', __version__[3]
end
if __version__[0:2] > __oldversion__[0:2]
# Current version is newer.
print 'Detected new release:', __oldversion__, '=>', __version__
end
end
46 changes: 46 additions & 0 deletions doomsday/libdeng2/modules/recutil.de
@@ -0,0 +1,46 @@
# The Doomsday Engine Project -- libdeng2
#
# Copyright (c) 2012-2013 Jaakko Keränen <jaakko.keranen@iki.fi>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/>.

#----------------------------------------------------------------------------
# Utility routines for manipulating Records

def copyMissingMembers(src, dest)
# Checks through 'src' to see if there are any variables or
# records not present in 'dest', and if those are found, inserts
# the missing members to 'dest'. Private keys in 'src' are ignored.
# - src: Source record.
# - dest: Destination record.
print "inserting missing members"

for name in dictkeys(members(src))
# Private members should be ignored.
if name[:2] == "__": continue

print "Checking member", name
if not name in members(dest)
if name in subrecords(src)
print "=> adding subrecord", name
dest[name] = Record()
else
print "=> setting member", name, "=", src[name]
dest[name] = src[name]
end
end

if name in subrecords(src): copyMissingMembers(src[name], dest[name])
end
end
11 changes: 4 additions & 7 deletions doomsday/libdeng2/src/core/app.cpp
Expand Up @@ -86,8 +86,7 @@ struct App::Instance
binFolder.attach(new DirectoryFeed(app.nativeBinaryPath()));
}
fs.makeFolder("/data").attach(new DirectoryFeed(appDir / "../Resources"));
fs.makeFolder("/config").attach(new DirectoryFeed(appDir / "../Resources/config"));
//fs.makeFolder("/modules").attach(new DirectoryFeed("Resources/modules"));
fs.makeFolder("/modules").attach(new DirectoryFeed(appDir / "../Resources/modules"));

#elif WIN32
if(allowPlugins)
Expand All @@ -96,17 +95,15 @@ struct App::Instance
}
NativePath appDir = appPath.fileNamePath();
fs.makeFolder("/data").attach(new DirectoryFeed(appDir / "..\\data"));
fs.makeFolder("/config").attach(new DirectoryFeed(appDir / "..\\config"));
//fs.>makeFolder("/modules").attach(new DirectoryFeed("data\\modules"));
fs.makeFolder("/modules").attach(new DirectoryFeed(appDir / "..\\modules"));

#else // UNIX
if(allowPlugins)
{
binFolder.attach(new DirectoryFeed(app.nativeBinaryPath()));
}
fs.makeFolder("/data").attach(new DirectoryFeed(app.nativeBasePath() / "data"));
fs.makeFolder("/config").attach(new DirectoryFeed(app.nativeBasePath() / "config"));
//fs.makeFolder("/modules").attach(new DirectoryFeed("data/modules"));
fs.makeFolder("/modules").attach(new DirectoryFeed(app.nativeBasePath() / "modules"));
#endif

// User's home folder.
Expand Down Expand Up @@ -272,7 +269,7 @@ void App::initSubsystems(SubsystemInitFlags flags)
d->persistentData = &homeFolder().locate<PackageFolder>("persist.pack").archive();

// The configuration.
d->config = new Config("/config/deng.de");
d->config = new Config("/modules/Config.de");
d->config->read();

LogBuffer &logBuf = LogBuffer::appBuffer();
Expand Down
16 changes: 9 additions & 7 deletions doomsday/tests/config_test.pri
@@ -1,10 +1,12 @@
include(../config.pri)
include(../dep_deng2.pri)

cfg.files = $$DENG_CONFIG_DIR/deng.de
mod.files = \
$$DENG_MODULES_DIR/Config.de \
$$DENG_MODULES_DIR/recutil.de

macx {
cfg.path = Contents/Resources/config
mod.path = Contents/Resources/modules

defineTest(deployTest) {
# Arg 1: target name (without .app)
Expand All @@ -17,27 +19,27 @@ macx {
# Fix the dynamic linker paths so they point to ../Frameworks/ inside the bundle.
fixInstallName($${1}.app/Contents/MacOS/$${1}, libdeng2.2.dylib, ..)

QMAKE_BUNDLE_DATA += cfg
QMAKE_BUNDLE_DATA += mod
export(QMAKE_BUNDLE_DATA)
}
}
else:win32 {
CONFIG += console

target.path = $$DENG_BIN_DIR
cfg.path = $$DENG_DATA_DIR/config
mod.path = $$DENG_DATA_DIR/modules

defineTest(deployTest) {
INSTALLS += cfg target
INSTALLS += mod target
export(INSTALLS)
}
}
else {
target.path = $$DENG_BIN_DIR
cfg.path = $$DENG_DATA_DIR/config
mod.path = $$DENG_DATA_DIR/modules

defineTest(deployTest) {
INSTALLS += cfg target
INSTALLS += mod target
export(INSTALLS)
}
}

0 comments on commit 172548d

Please sign in to comment.