Initial commit

pull/1/head
Marco Cawthorne 3 years ago
commit 600a90924e

@ -0,0 +1,275 @@
cmake_minimum_required(VERSION 2.8.12 FATAL_ERROR)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
project(WorldSpawn C CXX)
option(BUILD_RADIANT "Build the GUI" ON)
if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set(CMAKE_INSTALL_PREFIX "${PROJECT_SOURCE_DIR}/install" CACHE PATH "..." FORCE)
endif ()
#-----------------------------------------------------------------------
# Version
#-----------------------------------------------------------------------
# CMake 3.0+ would allow this in project()
set(WorldSpawn_VERSION_MAJOR 1)
set(WorldSpawn_VERSION_MINOR 0)
set(WorldSpawn_VERSION_PATCH 0)
set(WorldSpawn_VERSION "${WorldSpawn_VERSION_MAJOR}.${WorldSpawn_VERSION_MINOR}.${WorldSpawn_VERSION_PATCH}")
SET(CMAKE_C_COMPILER gcc-9)
SET(CMAKE_CXX_COMPILER g++-9)
file(WRITE "${PROJECT_BINARY_DIR}/WorldSpawn_MAJOR" ${WorldSpawn_VERSION_MAJOR})
file(WRITE "${PROJECT_BINARY_DIR}/WorldSpawn_MINOR" ${WorldSpawn_VERSION_MINOR})
file(WRITE "${PROJECT_BINARY_DIR}/WorldSpawn_PATCH" ${WorldSpawn_VERSION_PATCH})
#set(WorldSpawn_ABOUTMSG "Custom build" CACHE STRING "About message")
find_package(Git REQUIRED)
execute_process(
COMMAND ${GIT_EXECUTABLE} rev-parse --short HEAD
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
OUTPUT_VARIABLE GIT_VERSION
OUTPUT_STRIP_TRAILING_WHITESPACE
)
set(WorldSpawn_VERSION_STRING "${WorldSpawn_VERSION}n")
if (GIT_VERSION)
set(WorldSpawn_VERSION_STRING "${WorldSpawn_VERSION_STRING}-git-${GIT_VERSION}")
endif ()
message(STATUS "Building ${PROJECT_NAME} ${WorldSpawn_VERSION_STRING} ${WorldSpawn_ABOUTMSG}")
#-----------------------------------------------------------------------
# Language standard
#-----------------------------------------------------------------------
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
if (CMAKE_VERSION VERSION_LESS "3.1")
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR CMAKE_COMPILER_IS_GNUCXX)
include(CheckCXXCompilerFlag)
check_cxx_compiler_flag(--std=c++${CMAKE_CXX_STANDARD} STD_CXX)
if (STD_CXX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --std=c++${CMAKE_CXX_STANDARD}")
else ()
message(SEND_ERROR "Requires C++${CMAKE_CXX_STANDARD} or better")
endif ()
else ()
message(WARNING "Unrecognized compiler: ${CMAKE_CXX_COMPILER_ID}, make sure it supports C++${CMAKE_CXX_STANDARD}")
endif ()
endif ()
#-----------------------------------------------------------------------
# Flags
#-----------------------------------------------------------------------
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions -fno-rtti")
macro(addflags_c args)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${args}")
endmacro()
macro(addflags_cxx args)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${args}")
endmacro()
macro(addflags args)
addflags_c("${args}")
addflags_cxx("${args}")
endmacro()
addflags("-fno-strict-aliasing")
if (NOT WIN32)
addflags("-fvisibility=hidden")
endif ()
if ("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
#disabled due to GTK bug addflags("-Werror")
addflags("-pedantic-errors")
endif ()
addflags("-Wall")
addflags("-Wextra")
addflags("-pedantic")
addflags_c("-Wno-deprecated-declarations") # vfs.c: g_strdown
addflags("-Wno-unused-function")
addflags("-Wno-unused-variable")
addflags("-Wno-unused-parameter")
set(CMAKE_POSITION_INDEPENDENT_CODE 1)
set(GTK_TARGET 2 CACHE STRING "GTK target")
add_definitions(-DGTK_TARGET=${GTK_TARGET})
#-----------------------------------------------------------------------
# Defs
#-----------------------------------------------------------------------
add_definitions(-DWorldSpawn_VERSION="${WorldSpawn_VERSION}")
add_definitions(-DWorldSpawn_MAJOR_VERSION="${WorldSpawn_VERSION_MAJOR}")
add_definitions(-DWorldSpawn_MINOR_VERSION="${WorldSpawn_VERSION_MINOR}")
add_definitions(-DWorldSpawn_PATCH_VERSION="${WorldSpawn_VERSION_PATCH}")
add_definitions(-DWorldSpawn_ABOUTMSG="${WorldSpawn_ABOUT}")
if (NOT CMAKE_BUILD_TYPE MATCHES Release)
add_definitions(-D_DEBUG=1)
endif ()
macro(disable_deprecated name gtk2only)
add_definitions(-D${name}_DISABLE_SINGLE_INCLUDES)
if ((${gtk2only} EQUAL 0) OR (GTK_TARGET EQUAL 2))
add_definitions(-D${name}_DISABLE_DEPRECATED)
endif ()
endmacro()
disable_deprecated(ATK 0)
disable_deprecated(G 0)
disable_deprecated(GDK 0)
disable_deprecated(GDK_PIXBUF 0)
disable_deprecated(GTK 1)
disable_deprecated(PANGO 0)
if (APPLE)
option(XWINDOWS "Build against X11" ON)
add_definitions(
-DPOSIX=1
)
elseif (WIN32)
add_definitions(
-DWIN32=1
-D_WIN32=1
)
else ()
set(XWINDOWS ON)
add_definitions(
-DPOSIX=1
)
endif ()
if (XWINDOWS)
find_package(X11 REQUIRED)
include_directories(${X11_INCLUDE_DIR})
add_definitions(-DXWINDOWS=1)
endif ()
include_directories("${PROJECT_SOURCE_DIR}/include")
include_directories("${PROJECT_SOURCE_DIR}/libs")
if (WIN32 AND NOT CMAKE_CROSSCOMPILING)
set(BUNDLE_LIBRARIES_DEFAULT ON)
else ()
set(BUNDLE_LIBRARIES_DEFAULT OFF)
endif ()
option(BUNDLE_LIBRARIES "Bundle libraries" ${BUNDLE_LIBRARIES_DEFAULT})
macro(copy_dlls target)
if (BUNDLE_LIBRARIES)
add_custom_command(TARGET ${target} POST_BUILD
COMMAND bash
ARGS -c "ldd '$<TARGET_FILE:${target}>' | grep -v /c/Windows | awk '{ print $1 }' | while read dll; do cp \"$(which $dll)\" '${PROJECT_BINARY_DIR}'; done"
VERBATIM
)
endif ()
endmacro()
#-----------------------------------------------------------------------
# Libraries
#-----------------------------------------------------------------------
add_subdirectory(libs)
add_subdirectory(include)
#-----------------------------------------------------------------------
# Plugins
#-----------------------------------------------------------------------
if (BUILD_RADIANT)
add_subdirectory(contrib)
endif ()
#-----------------------------------------------------------------------
# Modules
#-----------------------------------------------------------------------
if (BUILD_RADIANT)
add_subdirectory(plugins)
endif ()
#-----------------------------------------------------------------------
# Radiant
#-----------------------------------------------------------------------
if (CMAKE_EXECUTABLE_SUFFIX)
string(REGEX REPLACE "^[.]" "" WorldSpawn_EXECUTABLE ${CMAKE_EXECUTABLE_SUFFIX})
else ()
execute_process(
COMMAND uname -m
OUTPUT_VARIABLE WorldSpawn_EXECUTABLE
OUTPUT_STRIP_TRAILING_WHITESPACE
)
endif ()
macro(radiant_tool name)
add_executable(${name} ${ARGN})
install(
TARGETS ${name}
RUNTIME DESTINATION .
)
if (NOT (CMAKE_EXECUTABLE_SUFFIX STREQUAL ".${WorldSpawn_EXECUTABLE}"))
add_custom_command(TARGET ${name} POST_BUILD
COMMAND ln -f -s "$<TARGET_FILE_NAME:${name}>" "${PROJECT_BINARY_DIR}/${name}.${WorldSpawn_EXECUTABLE}"
VERBATIM
)
install(CODE "execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink
${name}${CMAKE_EXECUTABLE_SUFFIX} ${CMAKE_INSTALL_PREFIX}/${name}.${WorldSpawn_EXECUTABLE})
")
endif ()
endmacro()
if (BUILD_RADIANT)
add_subdirectory(radiant _radiant)
set_target_properties(worldspawn PROPERTIES
COMPILE_DEFINITIONS WorldSpawn_EXECUTABLE="${WorldSpawn_EXECUTABLE}"
)
endif ()
#-----------------------------------------------------------------------
# Tools
#-----------------------------------------------------------------------
add_subdirectory(tools)
file(GLOB DATA_FILES "${PROJECT_SOURCE_DIR}/resources/*")
if (NOT (PROJECT_SOURCE_DIR STREQUAL PROJECT_BINARY_DIR))
# Copy data files from sources to the build directory
message(STATUS "Copying data files")
file(COPY ${DATA_FILES} DESTINATION "${PROJECT_BINARY_DIR}")
endif ()
#-----------------------------------------------------------------------
# Install
#-----------------------------------------------------------------------
install(
FILES
"${PROJECT_BINARY_DIR}/WorldSpawn_MAJOR"
"${PROJECT_BINARY_DIR}/WorldSpawn_MINOR"
"${PROJECT_BINARY_DIR}/WorldSpawn_PATCH"
DESTINATION .
)
install(
DIRECTORY
resources/
DESTINATION .
)
install(
DIRECTORY
DESTINATION .
OPTIONAL
)
include(cmake/scripts/package.cmake)

@ -0,0 +1,340 @@
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users. This
General Public License applies to most of the Free Software
Foundation's software and to any other program whose authors commit to
using it. (Some other Free Software Foundation software is covered by
the GNU Library General Public License instead.) You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.
To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have. You must make sure that they, too, receive or can get the
source code. And you must show them these terms so they know their
rights.
We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.
Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software. If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.
Finally, any free program is threatened constantly by software
patents. We wish to avoid the danger that redistributors of a free
program will individually obtain patent licenses, in effect making the
program proprietary. To prevent this, we have made it clear that any
patent must be licensed for everyone's free use or not licensed at all.
The precise terms and conditions for copying, distribution and
modification follow.
GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License applies to any program or other work which contains
a notice placed by the copyright holder saying it may be distributed
under the terms of this General Public License. The "Program", below,
refers to any such program or work, and a "work based on the Program"
means either the Program or any derivative work under copyright law:
that is to say, a work containing the Program or a portion of it,
either verbatim or with modifications and/or translated into another
language. (Hereinafter, translation is included without limitation in
the term "modification".) Each licensee is addressed as "you".
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running the Program is not restricted, and the output from the Program
is covered only if its contents constitute a work based on the
Program (independent of having been made by running the Program).
Whether that is true depends on what the Program does.
1. You may copy and distribute verbatim copies of the Program's
source code as you receive it, in any medium, provided that you
conspicuously and appropriately publish on each copy an appropriate
copyright notice and disclaimer of warranty; keep intact all the
notices that refer to this License and to the absence of any warranty;
and give any other recipients of the Program a copy of this License
along with the Program.
You may charge a fee for the physical act of transferring a copy, and
you may at your option offer warranty protection in exchange for a fee.
2. You may modify your copy or copies of the Program or any portion
of it, thus forming a work based on the Program, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a) You must cause the modified files to carry prominent notices
stating that you changed the files and the date of any change.
b) You must cause any work that you distribute or publish, that in
whole or in part contains or is derived from the Program or any
part thereof, to be licensed as a whole at no charge to all third
parties under the terms of this License.
c) If the modified program normally reads commands interactively
when run, you must cause it, when started running for such
interactive use in the most ordinary way, to print or display an
announcement including an appropriate copyright notice and a
notice that there is no warranty (or else, saying that you provide
a warranty) and that users may redistribute the program under
these conditions, and telling the user how to view a copy of this
License. (Exception: if the Program itself is interactive but
does not normally print such an announcement, your work based on
the Program is not required to print an announcement.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Program, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Program.
In addition, mere aggregation of another work not based on the Program
with the Program (or with a work based on the Program) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may copy and distribute the Program (or a work based on it,
under Section 2) in object code or executable form under the terms of
Sections 1 and 2 above provided that you also do one of the following:
a) Accompany it with the complete corresponding machine-readable
source code, which must be distributed under the terms of Sections
1 and 2 above on a medium customarily used for software interchange; or,
b) Accompany it with a written offer, valid for at least three
years, to give any third party, for a charge no more than your
cost of physically performing source distribution, a complete
machine-readable copy of the corresponding source code, to be
distributed under the terms of Sections 1 and 2 above on a medium
customarily used for software interchange; or,
c) Accompany it with the information you received as to the offer
to distribute corresponding source code. (This alternative is
allowed only for noncommercial distribution and only if you
received the program in object code or executable form with such
an offer, in accord with Subsection b above.)
The source code for a work means the preferred form of the work for
making modifications to it. For an executable work, complete source
code means all the source code for all modules it contains, plus any
associated interface definition files, plus the scripts used to
control compilation and installation of the executable. However, as a
special exception, the source code distributed need not include
anything that is normally distributed (in either source or binary
form) with the major components (compiler, kernel, and so on) of the
operating system on which the executable runs, unless that component
itself accompanies the executable.
If distribution of executable or object code is made by offering
access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.
4. You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License. Any attempt
otherwise to copy, modify, sublicense or distribute the Program is
void, and will automatically terminate your rights under this License.
However, parties who have received copies, or rights, from you under
this License will not have their licenses terminated so long as such
parties remain in full compliance.
5. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Program or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Program (or any work based on the
Program), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Program or works based on it.
6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the
original licensor to copy, distribute or modify the Program subject to
these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.
7. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Program at all. For example, if a patent
license would not permit royalty-free redistribution of the Program by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Program.
If any portion of this section is held invalid or unenforceable under
any particular circumstance, the balance of the section is intended to
apply and the section as a whole is intended to apply in other
circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system, which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
8. If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License
may add an explicit geographical distribution limitation excluding
those countries, so that distribution is permitted only in or among
countries not thus excluded. In such case, this License incorporates
the limitation as if written in the body of this License.
9. The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the Program
specifies a version number of this License which applies to it and "any
later version", you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation. If the Program does not specify a version number of
this License, you may choose any version ever published by the Free Software
Foundation.
10. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission. For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this. Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.
NO WARRANTY
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION.
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
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, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Also add information on how to contact you by electronic and paper mail.
If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:
Gnomovision version 69, Copyright (C) year name of author
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, the commands you use may
be called something other than `show w' and `show c'; they could even be
mouse-clicks or menu items--whatever suits your program.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the program, if
necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
`Gnomovision' (which makes passes at compilers) written by James Hacker.
<signature of Ty Coon>, 1 April 1989
Ty Coon, President of Vice
This General Public License does not permit incorporating your program into
proprietary programs. If your program is a subroutine library, you may
consider it more useful to permit linking proprietary applications with the
library. If this is what you want to do, use the GNU Library General
Public License instead of this License.

@ -0,0 +1,36 @@
LICENSE ( last update: Wed Feb 8 17:16:40 CST 2006 )
-----------------------------------------------------
There are 3 license types used throughout GtkRadiant source code.
BSD - modified Berkeley Software Distribution license
( each BSD licensed source file starts with the appropriate header )
LGPL - GNU Lesser General Public License v2.1
( see LGPL at the root of the tree )
GPL - GNU General Public License
( see GPL at the root of the tree )
How do I check which license applies to a given part of the source code?
Each source file in the tree comes with a license header which explains what
license applies. To sum up shortly:
GPL: ( except some files contributed by Loki Software under BSD license )
GtkRadiant Core
GtkRadiant Modules
GtkRadiant Libraries
Quake III Tools
Quake II Tools
Background2D Plugin
HydraToolz Plugin
BSD:
JPEG Library
MD5 Library
DDS Library
PicoModel Library
PrtView Plugin
LGPL
BobToolz Plugin
GenSurf Plugin

@ -0,0 +1,2 @@
#!/bin/sh
zip worldspawn_bin.zip -@ < build_contents.txt

@ -0,0 +1,150 @@
WorldSpawn.app
WorldSpawn.app/base
WorldSpawn.app/base/textures
WorldSpawn.app/base/textures/radiant
WorldSpawn.app/base/textures/radiant/notex.png
WorldSpawn.app/base/textures/radiant/shadernotex.png
WorldSpawn.app/bitmaps
WorldSpawn.app/bitmaps/black.png
WorldSpawn.app/bitmaps/brush_flipx.png
WorldSpawn.app/bitmaps/brush_flipy.png
WorldSpawn.app/bitmaps/brush_flipz.png
WorldSpawn.app/bitmaps/brush_rotatex.png
WorldSpawn.app/bitmaps/brush_rotatey.png
WorldSpawn.app/bitmaps/brush_rotatez.png
WorldSpawn.app/bitmaps/cap_bevel.png
WorldSpawn.app/bitmaps/cap_curve.png
WorldSpawn.app/bitmaps/cap_cylinder.png
WorldSpawn.app/bitmaps/cap_endcap.png
WorldSpawn.app/bitmaps/cap_ibevel.png
WorldSpawn.app/bitmaps/cap_iendcap.png
WorldSpawn.app/bitmaps/console.png
WorldSpawn.app/bitmaps/dontselectcurve.png
WorldSpawn.app/bitmaps/dontselectmodel.png
WorldSpawn.app/bitmaps/ellipsis.png
WorldSpawn.app/bitmaps/entities.png
WorldSpawn.app/bitmaps/file_open.png
WorldSpawn.app/bitmaps/file_save.png
WorldSpawn.app/bitmaps/icon.png
WorldSpawn.app/bitmaps/lightinspector.png
WorldSpawn.app/bitmaps/logo.png
WorldSpawn.app/bitmaps/modify_edges.png
WorldSpawn.app/bitmaps/modify_faces.png
WorldSpawn.app/bitmaps/modify_vertices.png
WorldSpawn.app/bitmaps/noFalloff.png
WorldSpawn.app/bitmaps/notex.png
WorldSpawn.app/bitmaps/patch_bend.png
WorldSpawn.app/bitmaps/patch_drilldown.png
WorldSpawn.app/bitmaps/patch_insdel.png
WorldSpawn.app/bitmaps/patch_showboundingbox.png
WorldSpawn.app/bitmaps/patch_weld.png
WorldSpawn.app/bitmaps/patch_wireframe.png
WorldSpawn.app/bitmaps/popup_selection.png
WorldSpawn.app/bitmaps/redo.png
WorldSpawn.app/bitmaps/refresh_models.png
WorldSpawn.app/bitmaps/scalelockx.png
WorldSpawn.app/bitmaps/scalelocky.png
WorldSpawn.app/bitmaps/scalelockz.png
WorldSpawn.app/bitmaps/selection_csgmerge.png
WorldSpawn.app/bitmaps/selection_csgsubtract.png
WorldSpawn.app/bitmaps/selection_makehollow.png
WorldSpawn.app/bitmaps/selection_makeroom.png
WorldSpawn.app/bitmaps/selection_selectcompletetall.png
WorldSpawn.app/bitmaps/selection_selectinside.png
WorldSpawn.app/bitmaps/selection_selectpartialtall.png
WorldSpawn.app/bitmaps/selection_selecttouching.png
WorldSpawn.app/bitmaps/select_mouseresize.png
WorldSpawn.app/bitmaps/select_mouserotate.png
WorldSpawn.app/bitmaps/select_mousescale.png
WorldSpawn.app/bitmaps/select_mousetranslate.png
WorldSpawn.app/bitmaps/shadernotex.png
WorldSpawn.app/bitmaps/show_entities.png
WorldSpawn.app/bitmaps/splash.png
WorldSpawn.app/bitmaps/texture_browser.png
WorldSpawn.app/bitmaps/texture_lock.png
WorldSpawn.app/bitmaps/textures_popup.png
WorldSpawn.app/bitmaps/undo.png
WorldSpawn.app/bitmaps/view_cameratoggle.png
WorldSpawn.app/bitmaps/view_cameraupdate.png
WorldSpawn.app/bitmaps/view_change.png
WorldSpawn.app/bitmaps/view_clipper.png
WorldSpawn.app/bitmaps/view_cubicclipping.png
WorldSpawn.app/bitmaps/view_entity.png
WorldSpawn.app/bitmaps/white.png
WorldSpawn.app/bitmaps/window1.png
WorldSpawn.app/bitmaps/window2.png
WorldSpawn.app/bitmaps/window3.png
WorldSpawn.app/bitmaps/window4.png
WorldSpawn.app/games
WorldSpawn.app/games/tw.game
WorldSpawn.app/gl
WorldSpawn.app/gl/lighting_DBS_omni_fp.glp
WorldSpawn.app/gl/lighting_DBS_omni_fp.glsl
WorldSpawn.app/gl/lighting_DBS_omni_vp.glp
WorldSpawn.app/gl/lighting_DBS_omni_vp.glsl
WorldSpawn.app/gl/lighting_DBS_XY_Z_arbfp1.cg
WorldSpawn.app/gl/lighting_DBS_XY_Z_arbvp1.cg
WorldSpawn.app/gl/utils.cg
WorldSpawn.app/gl/zfill_arbfp1.cg
WorldSpawn.app/gl/zfill_arbvp1.cg
WorldSpawn.app/gl/zfill_fp.glp
WorldSpawn.app/gl/zfill_fp.glsl
WorldSpawn.app/gl/zfill_vp.glp
WorldSpawn.app/gl/zfill_vp.glsl
WorldSpawn.app/global.xlink
WorldSpawn.app/modules
WorldSpawn.app/modules/libarchivezip.so
WorldSpawn.app/modules/libentity.so
WorldSpawn.app/modules/libimage.so
WorldSpawn.app/modules/libiqmmodel.so
WorldSpawn.app/modules/libmapq3.so
WorldSpawn.app/modules/libmodel.so
WorldSpawn.app/modules/libshaders.so
WorldSpawn.app/modules/libvfspk3.so
WorldSpawn.app/plugins
WorldSpawn.app/plugins/bitmaps
WorldSpawn.app/plugins/bitmaps/bobtoolz_caulk.png
WorldSpawn.app/plugins/bitmaps/bobtoolz_cleanup.png
WorldSpawn.app/plugins/bitmaps/bobtoolz_dropent.png
WorldSpawn.app/plugins/bitmaps/bobtoolz_merge.png
WorldSpawn.app/plugins/bitmaps/bobtoolz_poly.png
WorldSpawn.app/plugins/bitmaps/bobtoolz_splitcol.png
WorldSpawn.app/plugins/bitmaps/bobtoolz_split.png
WorldSpawn.app/plugins/bitmaps/bobtoolz_splitrow.png
WorldSpawn.app/plugins/bitmaps/bobtoolz_trainpathplot.png
WorldSpawn.app/plugins/bitmaps/bobtoolz_treeplanter.png
WorldSpawn.app/plugins/bitmaps/bobtoolz_turnedge.png
WorldSpawn.app/plugins/bitmaps/ufoai_actorclip.png
WorldSpawn.app/plugins/bitmaps/ufoai_level1.png
WorldSpawn.app/plugins/bitmaps/ufoai_level2.png
WorldSpawn.app/plugins/bitmaps/ufoai_level3.png
WorldSpawn.app/plugins/bitmaps/ufoai_level4.png
WorldSpawn.app/plugins/bitmaps/ufoai_level5.png
WorldSpawn.app/plugins/bitmaps/ufoai_level6.png
WorldSpawn.app/plugins/bitmaps/ufoai_level7.png
WorldSpawn.app/plugins/bitmaps/ufoai_level8.png
WorldSpawn.app/plugins/bitmaps/ufoai_nodraw.png
WorldSpawn.app/plugins/bitmaps/ufoai_stepon.png
WorldSpawn.app/plugins/bitmaps/ufoai_weaponclip.png
WorldSpawn.app/plugins/bt
WorldSpawn.app/plugins/bt/bt-el1.txt
WorldSpawn.app/plugins/bt/bt-el2.txt
WorldSpawn.app/plugins/bt/door-tex-trim.txt
WorldSpawn.app/plugins/bt/door-tex.txt
WorldSpawn.app/plugins/bt/tp_ent.txt
WorldSpawn.app/plugins/libbobtoolz.so
WorldSpawn.app/plugins/libbrushexport.so
WorldSpawn.app/plugins/libprtview.so
WorldSpawn.app/plugins/libshaderplug.so
WorldSpawn.app/plugins/libsunplug.so
WorldSpawn.app/tw.game
WorldSpawn.app/tw.game/default_build_menu.xml
WorldSpawn.app/tw.game/game.xlink
WorldSpawn.app/tw.game/wastes
WorldSpawn.app/tw.game/wastes/entities.def
WorldSpawn.app/Resources
WorldSpawn.app/Resources/Info-gnustep.plist
WorldSpawn.app/Resources/icon.tiff
WorldSpawn.app/vmap
WorldSpawn.app/worldspawn
WorldSpawn.app/WorldSpawn

@ -0,0 +1,21 @@
find_package(PkgConfig)
if (PKG_CONFIG_FOUND)
if (GLIB_FIND_REQUIRED)
set(_pkgconfig_REQUIRED REQUIRED)
endif ()
pkg_check_modules(GLIB ${_pkgconfig_REQUIRED} glib-2.0)
else ()
find_path(GLIB_INCLUDE_DIRS glib.h)
find_library(GLIB_LIBRARIES glib-2.0)
if (GLIB_INCLUDE_DIRS AND GLIB_LIBRARIES)
set(GLIB_FOUND 1)
if (NOT GLIB_FIND_QUIETLY)
message(STATUS "Found GLIB: ${GLIB_LIBRARIES}")
endif ()
elseif (GLIB_FIND_REQUIRED)
message(SEND_ERROR "Could not find GLIB")
elseif (NOT GLIB_FIND_QUIETLY)
message(STATUS "Could not find GLIB")
endif ()
endif ()
mark_as_advanced(GLIB_INCLUDE_DIRS GLIB_LIBRARIES)

@ -0,0 +1,21 @@
find_package(PkgConfig)
if (PKG_CONFIG_FOUND)
if (GTK2_FIND_REQUIRED)
set(_pkgconfig_REQUIRED REQUIRED)
endif ()
pkg_check_modules(GTK2 ${_pkgconfig_REQUIRED} gtk+-2.0)
else ()
find_path(GTK2_INCLUDE_DIRS gtk.h)
# find_library(GTK2_LIBRARIES)
if (GTK2_INCLUDE_DIRS AND GTK2_LIBRARIES)
set(GTK2_FOUND 1)
if (NOT GTK2_FIND_QUIETLY)
message(STATUS "Found GTK2: ${GTK2_LIBRARIES}")
endif ()
elseif (GTK2_FIND_REQUIRED)
message(SEND_ERROR "Could not find GTK2")
elseif (NOT GTK2_FIND_QUIETLY)
message(STATUS "Could not find GTK2")
endif ()
endif ()
mark_as_advanced(GTK2_INCLUDE_DIRS GTK2_LIBRARIES)

@ -0,0 +1,21 @@
find_package(PkgConfig)
if (PKG_CONFIG_FOUND)
if (GTK3_FIND_REQUIRED)
set(_pkgconfig_REQUIRED REQUIRED)
endif ()
pkg_check_modules(GTK3 ${_pkgconfig_REQUIRED} gtk+-3.0)
else ()
find_path(GTK3_INCLUDE_DIRS gtk.h)
# find_library(GTK3_LIBRARIES)
if (GTK3_INCLUDE_DIRS AND GTK3_LIBRARIES)
set(GTK3_FOUND 1)
if (NOT GTK3_FIND_QUIETLY)
message(STATUS "Found GTK3: ${GTK3_LIBRARIES}")
endif ()
elseif (GTK3_FIND_REQUIRED)
message(SEND_ERROR "Could not find GTK3")
elseif (NOT GTK3_FIND_QUIETLY)
message(STATUS "Could not find GTK3")
endif ()
endif ()
mark_as_advanced(GTK3_INCLUDE_DIRS GTK3_LIBRARIES)

@ -0,0 +1,27 @@
find_package(PkgConfig)
if (PKG_CONFIG_FOUND)
if (GtkGLExt_FIND_REQUIRED)
set(_pkgconfig_REQUIRED REQUIRED)
endif ()
if (XWINDOWS)
pkg_check_modules(GtkGLExt ${_pkgconfig_REQUIRED} gtkglext-x11-1.0)
elseif (WIN32)
pkg_check_modules(GtkGLExt ${_pkgconfig_REQUIRED} gtkglext-win32-1.0)
else ()
pkg_check_modules(GtkGLExt ${_pkgconfig_REQUIRED} gtkglext-quartz-1.0)
endif ()
else ()
find_path(GtkGLExt_INCLUDE_DIRS gtkglwidget.h)
# find_library(GtkGLExt_LIBRARIES)
if (GtkGLExt_INCLUDE_DIRS AND GtkGLExt_LIBRARIES)
set(GtkGLExt_FOUND 1)
if (NOT GtkGLExt_FIND_QUIETLY)
message(STATUS "Found GtkGLExt: ${GtkGLExt_LIBRARIES}")
endif ()
elseif (GtkGLExt_FIND_REQUIRED)
message(SEND_ERROR "Could not find GtkGLExt")
elseif (NOT GtkGLExt_FIND_QUIETLY)
message(STATUS "Could not find GtkGLExt")
endif ()
endif ()
mark_as_advanced(GtkGLExt_INCLUDE_DIRS GtkGLExt_LIBRARIES)

@ -0,0 +1,21 @@
find_package(PkgConfig)
if (PKG_CONFIG_FOUND)
if (Minizip_FIND_REQUIRED)
set(_pkgconfig_REQUIRED REQUIRED)
endif ()
pkg_check_modules(Minizip ${_pkgconfig_REQUIRED} minizip)
else ()
find_path(Minizip_INCLUDE_DIRS unzip.h)
# find_library(Minizip_LIBRARIES)
if (Minizip_INCLUDE_DIRS AND Minizip_LIBRARIES)
set(Minizip_FOUND 1)
if (NOT Minizip_FIND_QUIETLY)
message(STATUS "Found Minizip: ${Minizip_LIBRARIES}")
endif ()
elseif (Minizip_FIND_REQUIRED)
message(SEND_ERROR "Could not find Minizip")
elseif (NOT Minizip_FIND_QUIETLY)
message(STATUS "Could not find Minizip")
endif ()
endif ()
mark_as_advanced(Minizip_INCLUDE_DIRS Minizip_LIBRARIES)

@ -0,0 +1,23 @@
find_package(PkgConfig)
if (PKG_CONFIG_FOUND)
if (Pango_FIND_REQUIRED)
set(_pkgconfig_REQUIRED REQUIRED)
endif ()
pkg_search_module(Pango ${_pkgconfig_REQUIRED} pango pangocairo)
pkg_search_module(PangoFT2 ${_pkgconfig_REQUIRED} pangoft2)
else ()
# find_path(Pango_INCLUDE_DIRS)
# find_library(Pango_LIBRARIES)
if (Pango_INCLUDE_DIRS AND Pango_LIBRARIES)
set(Pango_FOUND 1)
if (NOT Pango_FIND_QUIETLY)
message(STATUS "Found Pango: ${Pango_LIBRARIES}")
endif ()
elseif (Pango_FIND_REQUIRED)
message(SEND_ERROR "Could not find Pango")
elseif (NOT Pango_FIND_QUIETLY)
message(STATUS "Could not find Pango")
endif ()
endif ()
mark_as_advanced(Pango_INCLUDE_DIRS Pango_LIBRARIES)
mark_as_advanced(PangoFT2_INCLUDE_DIRS PangoFT2_LIBRARIES)

@ -0,0 +1,16 @@
set(CPACK_PACKAGE_NAME "WorldSpawn")
set(CPACK_PACKAGE_VERSION_MAJOR "${WorldSpawn_VERSION_MAJOR}")
set(CPACK_PACKAGE_VERSION_MINOR "${WorldSpawn_VERSION_MINOR}")
set(CPACK_PACKAGE_VERSION_PATCH "${WorldSpawn_VERSION_PATCH}")
# binary: --target package
set(CPACK_GENERATOR "ZIP")
set(CPACK_STRIP_FILES 1)
# source: --target package_source
set(CPACK_SOURCE_GENERATOR "ZIP")
set(CPACK_SOURCE_IGNORE_FILES "/\\\\.git/;/build/;/install/")
# configure
include(InstallRequiredSystemLibraries)
include(CPack)

@ -0,0 +1 @@
cmake -G "Unix Makefiles" -H. -Bbuild -DCMAKE_BUILD_TYPE=Debug && cmake --build build -- -j$(nproc)

@ -0,0 +1 @@
cmake -G "Unix Makefiles" -H. -Bbuild -DCMAKE_BUILD_TYPE=Release && cmake --build build -- -j$(nproc)

@ -0,0 +1,16 @@
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/plugins")
add_custom_target(plugins)
macro(radiant_plugin name)
message(STATUS "Found Plugin ${name}")
add_library(${name} MODULE ${ARGN})
add_dependencies(plugins ${name})
copy_dlls(${name})
install(
TARGETS ${name}
LIBRARY DESTINATION plugins
)
endmacro()
add_subdirectory(brushexport)
add_subdirectory(prtview)

@ -0,0 +1,10 @@
radiant_plugin(brushexport
callbacks.cpp callbacks.h
export.cpp export.h
interface.cpp
plugin.cpp plugin.h
support.cpp support.h
)
target_include_directories(brushexport PRIVATE uilib)
target_link_libraries(brushexport PRIVATE uilib)

@ -0,0 +1,7 @@
; brushexport.def : Declares the module parameters for the DLL.
LIBRARY "BRUSHEXPORT"
EXPORTS
; Explicit exports can go here
Radiant_RegisterModules @1

@ -0,0 +1,148 @@
#include <glib.h>
#include <gtk/gtk.h>
#include <set>
#include "qerplugin.h"
#include "debugging/debugging.h"
#include "support.h"
#include "export.h"
// stuff from interface.cpp
void DestroyWindow();
namespace callbacks {
void OnDestroy(ui::Widget w, gpointer data)
{
DestroyWindow();
}
void OnExportClicked(ui::Button button, gpointer user_data)
{
auto window = ui::Window::from(lookup_widget(button, "w_plugplug2"));
ASSERT_TRUE(window);
const char *cpath = GlobalRadiant().m_pfnFileDialog(window, false, "Save as Obj", 0, 0, false, false, true);
if (!cpath) {
return;
}
std::string path(cpath);
// get ignore list from ui
std::set<std::string> ignore;
auto view = ui::TreeView::from(lookup_widget(button, "t_materialist"));
ui::ListStore list = ui::ListStore::from(gtk_tree_view_get_model(view));
GtkTreeIter iter;
gboolean valid = gtk_tree_model_get_iter_first(list, &iter);
while (valid) {
gchar *data;
gtk_tree_model_get(list, &iter, 0, &data, -1);
globalOutputStream() << data << "\n";
ignore.insert(std::string(data));
g_free(data);
valid = gtk_tree_model_iter_next(list, &iter);
}
for (std::set<std::string>::iterator it(ignore.begin()); it != ignore.end(); ++it) {
globalOutputStream() << it->c_str() << "\n";
}
// collapse mode
collapsemode mode = COLLAPSE_NONE;
auto radio = lookup_widget(button, "r_collapse");
ASSERT_TRUE(radio);
if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(radio))) {
mode = COLLAPSE_ALL;
} else {
radio = lookup_widget(button, "r_collapsebymaterial");
ASSERT_TRUE(radio);
if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(radio))) {
mode = COLLAPSE_BY_MATERIAL;
} else {
radio = lookup_widget(button, "r_nocollapse");
ASSERT_TRUE(radio);
ASSERT_TRUE(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(radio)));
mode = COLLAPSE_NONE;
}
}
// export materials?
auto toggle = lookup_widget(button, "t_exportmaterials");
ASSERT_TRUE(toggle);
bool exportmat = FALSE;
if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(toggle))) {
exportmat = TRUE;
}
// limit material names?
toggle = lookup_widget(button, "t_limitmatnames");
ASSERT_TRUE(toggle);
bool limitMatNames = FALSE;
if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(toggle)) && exportmat) {
limitMatNames = TRUE;
}
// create objects instead of groups?
toggle = lookup_widget(button, "t_objects");
ASSERT_TRUE(toggle);
bool objects = FALSE;
if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(toggle)) && exportmat) {
objects = TRUE;
}
// export
ExportSelection(ignore, mode, exportmat, path, limitMatNames, objects);
}
void OnAddMaterial(ui::Button button, gpointer user_data)
{
auto edit = ui::Entry::from(lookup_widget(button, "ed_materialname"));
ASSERT_TRUE(edit);
const gchar *name = gtk_entry_get_text(edit);
if (g_utf8_strlen(name, -1) > 0) {
ui::ListStore list = ui::ListStore::from(
gtk_tree_view_get_model(ui::TreeView::from(lookup_widget(button, "t_materialist"))));
list.append(0, name);
gtk_entry_set_text(edit, "");
}
}
void OnRemoveMaterial(ui::Button button, gpointer user_data)
{
ui::TreeView view = ui::TreeView::from(lookup_widget(button, "t_materialist"));
ui::ListStore list = ui::ListStore::from(gtk_tree_view_get_model(view));
auto sel = ui::TreeSelection::from(gtk_tree_view_get_selection(view));
GtkTreeIter iter;
if (gtk_tree_selection_get_selected(sel, 0, &iter)) {
gtk_list_store_remove(list, &iter);
}
}
void OnExportMatClicked(ui::Button button, gpointer user_data)
{
ui::Widget toggleLimit = lookup_widget(button, "t_limitmatnames");
ui::Widget toggleObject = lookup_widget(button, "t_objects");
if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button))) {
gtk_widget_set_sensitive(toggleLimit, TRUE);
gtk_widget_set_sensitive(toggleObject, TRUE);
} else {
gtk_widget_set_sensitive(toggleLimit, FALSE);
gtk_widget_set_sensitive(toggleObject, FALSE);
}
}
} // callbacks

@ -0,0 +1,16 @@
#include <uilib/uilib.h>
namespace callbacks {
void OnDestroy(ui::Widget, gpointer);
void OnExportClicked(ui::Button, gpointer);
void OnAddMaterial(ui::Button, gpointer);
void OnRemoveMaterial(ui::Button, gpointer);
void OnExportMatClicked(ui::Button button, gpointer);
} // callbacks

@ -0,0 +1,365 @@
#include "export.h"
#include "globaldefs.h"
#include "debugging/debugging.h"
#include "ibrush.h"
#include "iscenegraph.h"
#include "iselection.h"
#include "stream/stringstream.h"
#include "stream/textfilestream.h"
#include <map>
// this is very evil, but right now there is no better way
#include "../../radiant/brush.h"
// for limNames
const int MAX_MATERIAL_NAME = 20;
/*
Abstract baseclass for modelexporters
the class collects all the data which then gets
exported through the WriteToFile method.
*/
class ExportData {
public:
ExportData(const std::set<std::string> &ignorelist, collapsemode mode, bool limNames, bool objs);
virtual ~ExportData(void);
virtual void BeginBrush(Brush &b);
virtual void AddBrushFace(Face &f);
virtual void EndBrush(void);
virtual bool WriteToFile(const std::string &path, collapsemode mode) const = 0;
protected:
// a group of faces
class group {
public:
std::string name;
std::list<const Face *> faces;
};
std::list<group> groups;
private:
// "textures/common/caulk" -> "caulk"
void GetShaderNameFromShaderPath(const char *path, std::string &name);
group *current;
collapsemode mode;
const std::set<std::string> &ignorelist;
};
ExportData::ExportData(const std::set<std::string> &_ignorelist, collapsemode _mode, bool _limNames, bool _objs)
: mode(_mode),
ignorelist(_ignorelist)
{
current = 0;
// in this mode, we need just one group
if (mode == COLLAPSE_ALL) {
groups.push_back(group());
current = &groups.back();
current->name = "all";
}
}
ExportData::~ExportData(void)
{
}
void ExportData::BeginBrush(Brush &b)
{
// create a new group for each brush
if (mode == COLLAPSE_NONE) {
groups.push_back(group());
current = &groups.back();
StringOutputStream str(256);
str << "Brush" << (const unsigned int) groups.size();
current->name = str.c_str();
}
}
void ExportData::EndBrush(void)
{
// all faces of this brush were on the ignorelist, discard the emptygroup
if (mode == COLLAPSE_NONE) {
ASSERT_NOTNULL(current);
if (current->faces.empty()) {
groups.pop_back();
current = 0;
}
}
}
void ExportData::AddBrushFace(Face &f)
{
std::string shadername;
GetShaderNameFromShaderPath(f.GetShader(), shadername);
// ignore faces from ignore list
if (ignorelist.find(shadername) != ignorelist.end()) {
return;
}
if (mode == COLLAPSE_BY_MATERIAL) {
// find a group for this material
current = 0;
const std::list<group>::iterator end(groups.end());
for (std::list<group>::iterator it(groups.begin()); it != end; ++it) {
if (it->name == shadername) {
current = &(*it);
}
}
// no group found, create one
if (!current) {
groups.push_back(group());
current = &groups.back();
current->name = shadername;
}
}
ASSERT_NOTNULL(current);
// add face to current group
current->faces.push_back(&f);
#if GDEF_DEBUG
globalOutputStream() << "Added Face to group " << current->name.c_str() << "\n";
#endif
}
void ExportData::GetShaderNameFromShaderPath(const char *path, std::string &name)
{
std::string tmp(path);
size_t last_slash = tmp.find_last_of("/");
if (last_slash != std::string::npos && last_slash == (tmp.length() - 1)) {
name = path;
} else {
name = tmp.substr(last_slash + 1, tmp.length() - last_slash);
}
#if GDEF_DEBUG
globalOutputStream() << "Last: " << (const unsigned int) last_slash << " " << "length: "
<< (const unsigned int) tmp.length() << "Name: " << name.c_str() << "\n";
#endif
}
/*
Exporter writing facedata as wavefront object
*/
class ExportDataAsWavefront : public ExportData {
private:
bool expmat;
bool limNames;
bool objs;
public:
ExportDataAsWavefront(const std::set<std::string> &_ignorelist, collapsemode _mode, bool _expmat, bool _limNames,
bool _objs)
: ExportData(_ignorelist, _mode, _limNames, _objs)
{
expmat = _expmat;
limNames = _limNames;
objs = _objs;
}
bool WriteToFile(const std::string &path, collapsemode mode) const;
};
bool ExportDataAsWavefront::WriteToFile(const std::string &path, collapsemode mode) const
{
std::string objFile = path;
if (path.compare(path.length() - 4, 4, ".obj") != 0) {
objFile += ".obj";
}
std::string mtlFile = objFile.substr(0, objFile.length() - 4) + ".mtl";
std::set<std::string> materials;
TextFileOutputStream out(objFile.c_str());
if (out.failed()) {
globalErrorStream() << "Unable to open file\n";
return false;
}
out
<< "# Wavefront Objectfile exported with radiants brushexport plugin 3.0 by Thomas 'namespace' Nitschke, spam@codecreator.net\n\n";
if (expmat) {
size_t last = mtlFile.find_last_of("//");
std::string mtllib = mtlFile.substr(last + 1, mtlFile.size() - last).c_str();
out << "mtllib " << mtllib.c_str() << "\n";
}
unsigned int vertex_count = 0;
const std::list<ExportData::group>::const_iterator gend(groups.end());
for (std::list<ExportData::group>::const_iterator git(groups.begin()); git != gend; ++git) {
typedef std::multimap<std::string, std::string> bm;
bm brushMaterials;
typedef std::pair<std::string, std::string> String_Pair;
const std::list<const Face *>::const_iterator end(git->faces.end());
// submesh starts here
if (objs) {
out << "\no ";
} else {
out << "\ng ";
}
out << git->name.c_str() << "\n";
// material
if (expmat && mode == COLLAPSE_ALL) {
out << "usemtl material" << "\n\n";
materials.insert("material");
}
for (std::list<const Face *>::const_iterator it(git->faces.begin()); it != end; ++it) {
const Winding &w((*it)->getWinding());
// vertices
for (size_t i = 0; i < w.numpoints; ++i) {
out << "v " << FloatFormat(w[i].vertex.x(), 1, 6) << " " << FloatFormat(w[i].vertex.z(), 1, 6) << " "
<< FloatFormat(w[i].vertex.y(), 1, 6) << "\n";
}
}
out << "\n";
for (std::list<const Face *>::const_iterator it(git->faces.begin()); it != end; ++it) {
const Winding &w((*it)->getWinding());
// texcoords
for (size_t i = 0; i < w.numpoints; ++i) {
out << "vt " << FloatFormat(w[i].texcoord.x(), 1, 6) << " " << FloatFormat(w[i].texcoord.y(), 1, 6)
<< "\n";
}
}
for (std::list<const Face *>::const_iterator it(git->faces.begin()); it != end; ++it) {
const Winding &w((*it)->getWinding());
// faces
StringOutputStream faceLine(256);
faceLine << "\nf";
for (size_t i = 0; i < w.numpoints; ++i, ++vertex_count) {
faceLine << " " << vertex_count + 1 << "/" << vertex_count + 1;
}
if (mode != COLLAPSE_ALL) {
materials.insert((*it)->getShader().getShader());
brushMaterials.insert(String_Pair((*it)->getShader().getShader(), faceLine.c_str()));
} else {
out << faceLine.c_str();
}
}
if (mode != COLLAPSE_ALL) {
std::string lastMat;
std::string mat;