Skip to content

Commit

Permalink
Improved the build script, reorganized things a bit, and added licens…
Browse files Browse the repository at this point in the history
…ing info.
  • Loading branch information
emezeske committed Mar 10, 2011
1 parent 8e66947 commit b94184e
Show file tree
Hide file tree
Showing 34 changed files with 586 additions and 78 deletions.
3 changes: 3 additions & 0 deletions .gitignore
@@ -1,4 +1,7 @@
*.o
.sconf_temp
.sconsign.dblite
config.log
digbuild
tags
media/materials/textures/source
12 changes: 12 additions & 0 deletions COPYING
@@ -0,0 +1,12 @@
gpufrac 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/>.
339 changes: 339 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

45 changes: 44 additions & 1 deletion README
@@ -1 +1,44 @@
DigBuild is a simple Minecraft clone.
###########################################################################
# ABOUT
###########################################################################

Digbuild is an experimental project to create a voxel-based game with many
similarities to Minecraft (and many improvements as well).

###########################################################################
# DEPENDENCIES
###########################################################################

The following libraries are required to build Digbuild:

* Boost
* GMTL (see http://sourceforge.net/projects/ggt)
* SDL
* SDL Image
* GL
* GLU
* GLEW

###########################################################################
# BUILDING
###########################################################################

In the top-level Digbuild directory, run 'scons'. Depending on where your
Boost and GMTL header files are installed, you may need to use the following
options:

--boost_include_dir=<PATH>
--gmtl_include_dir=<PATH>

The following arguments may also be used to configure the build:

optimize=(1|0) # Build the binary with optimizations.
assert=(1|0) # Build the binary with assertions left in.
release=(1|0) # Strip the binary, etc.
profile=(1|0) # Build gprof profiling information into the binary.

The following build targets may be useful:

run # Run the binary (after building it if necessary).
prof # Run the binary and generate profiling output when it exits.
src/tags # Build an exuberant-ctags database file.
118 changes: 94 additions & 24 deletions SConstruct
@@ -1,15 +1,57 @@
import os, glob
import multiprocessing
import os
import subprocess

SetOption( 'num_jobs', 9 ) # Set this to the number of processors you have. TODO: Automate this.
HEADERS = Glob( 'src/*.h' )
SOURCES = Glob( 'src/*.cc' )
BINARY = 'digbuild'
LIBRARY_DEPENDENCIES = [ 'sdl', 'SDL_image', 'gl', 'glew', 'glu' ]
HEADER_DEPENDENCIES = [ 'boost/shared_ptr.hpp', 'gmtl/gmtl.h' ]
INCLUDE_DIRECTORY_NAMES = [ 'boost_include_dir', 'gmtl_include_dir' ]

sources = glob.glob( '*.cc' )
headers = glob.glob( '*.h' )
def CheckPackageConfig( context, library ):
context.Message( 'Checking for library %s...' % library )
if subprocess.call( [ 'pkg-config', '--exists', library ] ) == 0:
context.Result( 'ok' )
return True
else:
context.Result( 'failed' )
return False

CCFLAGS = [
'-isystem/usr/include/gmtl-0.5.2',
'-g',
'-ffast-math',
'-fassociative-math',
AddOption(
'--boost-include-dir',
dest = 'boost_include_dir',
nargs = 1,
type = 'string',
action = 'store',
metavar = 'DIR',
default = '/usr/include',
help = 'Boost header file directory'
)

AddOption(
'--gmtl-include-dir',
dest = 'gmtl_include_dir',
nargs = 1,
type = 'string',
action = 'store',
metavar = 'DIR',
default = '/usr/include/gmtl-0.5.2',
help = 'GMTL header file directory'
)

OPTIMIZE_BINARY = ARGUMENTS.get( 'optimize', 1 )
INCLUDE_ASSERTIONS = not ARGUMENTS.get( 'assert', 0 )
RELEASE_BUILD = ARGUMENTS.get( 'release', 0 )
PROFILE_BINARY = ARGUMENTS.get( 'profile', 0 )

env = Environment()
env.SetOption( 'num_jobs', multiprocessing.cpu_count() * 2 + 1 )

for variable in [ 'PATH', 'TERM', 'HOME', 'DISPLAY' ]:
env.Append( ENV = { variable : os.environ[variable] } )

env.Append( CCFLAGS = [
'-Wall',
'-W',
'-Wshadow',
Expand All @@ -19,25 +61,53 @@ CCFLAGS = [
'-Wredundant-decls',
'-Wno-unused',
'-Wno-deprecated'
]
] )

LINKFLAGS = []
for name in INCLUDE_DIRECTORY_NAMES:
directory = GetOption( name )
env.Append( CPPPATH = [ directory ] )
env.Append( CCFLAGS = [ '-isystem%s' % directory ] )

CCFLAGS += [ '-O3' ]
CCFLAGS += [ '-DNDEBUG' ]
LINKFLAGS += [ '-Wl,--strip-all' ]
if OPTIMIZE_BINARY:
env.Append( CCFLAGS = [ '-O3', '-ffast-math', '-fassociative-math' ] )

#CCFLAGS += [ '-pg' ]
#LINKFLAGS += [ '-pg' ]
if INCLUDE_ASSERTIONS:
env.Append( CCFLAGS = [ '-DNDEBUG' ] )

env = Environment()
env.Append( ENV = {'PATH':os.environ['PATH'], 'TERM':os.environ['TERM'], 'HOME':os.environ['HOME']} ) # Environment variables required by colorgcc.
env.Append( LIBS = [ 'SDL', 'SDL_image', 'GL', 'GLU', 'GLEW', 'rt' ] )
env.Append( CCFLAGS = CCFLAGS )
env.Append( LINKFLAGS = LINKFLAGS )
if RELEASE_BUILD:
env.Append( LINKFLAGS = [ '-Wl,--strip-all' ] )
else:
env.Append( CCFLAGS = [ '-g' ] )

if PROFILE_BINARY:
env.Append( CCFLAGS = [ '-pg' ] )
env.Append( LINKFLAGS = [ '-pg' ] )

conf = Configure( env, custom_tests = { 'CheckPackageConfig' : CheckPackageConfig } )

for header in HEADER_DEPENDENCIES:
if not conf.CheckCXXHeader( header ):
print 'Required header file %s could not be found. Aborting.' % header
Exit( 1 )

for library in LIBRARY_DEPENDENCIES:
if not conf.CheckPackageConfig( library ):
print '*** Required library %s could not be found. Aborting.' % library
Exit( 1 )

env = conf.Finish()

for library in LIBRARY_DEPENDENCIES:
env.MergeFlags( [ '!pkg-config %s --cflags --libs' % library ] )

env.Program( source = SOURCES, target = BINARY )
env.Command( 'src/tags', SOURCES + HEADERS, 'ctags -o $TARGET $SOURCES' )

# scons && ./digbuild && gprof digbuild > prof
env.Command( 'prof', BINARY, './%(binary)s && gprof %(binary)s > prof' % { 'binary' : BINARY } )
env.Clean( 'prof', [ 'prof', 'gmon.out' ] )
env.AlwaysBuild( 'prof' )

env.Program( source = sources, target = 'digbuild' )
env.Command( 'run', BINARY, './' + BINARY )
env.AlwaysBuild( 'run' )

env.Command( 'tags', sources + headers, 'ctags -o $TARGET $SOURCES' )
env.Default( [ BINARY, 'src/tags' ] )
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion camera.cc → src/camera.cc
Expand Up @@ -52,7 +52,7 @@ void Camera::handle_mouse_motion( int xrel, int yrel )
else if ( pitch_ < -90.0f ) pitch_ = -90.f;
}

Vector3f Camera::get_direction()
Vector3f Camera::get_direction() const
{
float
pitch_radians = pitch_ * gmtl::Math::PI / 180.0f,
Expand Down
19 changes: 11 additions & 8 deletions camera.h → src/camera.h
Expand Up @@ -12,7 +12,9 @@ struct Camera
void translate() const;
void do_one_step( float step_time );
void handle_mouse_motion( int xrel, int yrel );
Vector3f get_direction();

Vector3f get_direction() const;
Vector3f get_position() const { return position_; }

void fast_move_mode( bool m ) { moving_fast_ = m; }
void move_forward( bool m ) { moving_forward_ = m; }
Expand All @@ -22,21 +24,22 @@ struct Camera
void move_up( bool m ) { moving_up_ = m; }
void move_down( bool m ) { moving_down_ = m; }

Vector3f position_;

Scalar
mouse_sensitivity_,
pitch_,
yaw_;

private:

void move_forward( Scalar movement_units );
void strafe( Scalar movement_units );

static const float
CAMERA_SPEED = 30.0f,
CAMERA_FAST_MODE_FACTOR = 5.0f;

Vector3f position_;

Scalar
mouse_sensitivity_,
pitch_,
yaw_;

bool
moving_fast_,
moving_forward_,
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit b94184e

Please sign in to comment.