Browse Source

Rewrite BaseApp to newer Ogre3D SDK

master
Dashie der otter 1 year ago
parent
commit
969ec8ed14
Signed by: dashie <rhaamo@leloop.org> GPG Key ID: C2D57B325840B755
7 changed files with 1515 additions and 1289 deletions
  1. +176
    -176
      CMakeLists.txt
  2. +187
    -0
      src/BaseApp.cpp
  3. +38
    -0
      src/BaseApp.h
  4. +1009
    -863
      src/CubeWorld.cpp
  5. +101
    -92
      src/CubeWorld.h
  6. +2
    -156
      src/old/BaseApplication.cpp
  7. +2
    -2
      src/old/BaseApplication.h

+ 176
- 176
CMakeLists.txt View File

@@ -10,14 +10,14 @@ cmake_policy(SET CMP0003 NEW)

# Use relative paths
# This is mostly to reduce path size for command-line limits on windows
if(WIN32)
# This seems to break Xcode projects so definitely don't enable on Apple builds
set(CMAKE_USE_RELATIVE_PATHS true)
set(CMAKE_SUPPRESS_REGENERATION true)
set(CMAKE_MODULE_PATH "$ENV{OGRE_HOME}/CMake/;${CMAKE_MODULE_PATH}")
set(OGRE_SAMPLES_INCLUDEPATH
$ENV{OGRE_HOME}/Samples/include)
endif()
if (WIN32)
# This seems to break Xcode projects so definitely don't enable on Apple builds
set(CMAKE_USE_RELATIVE_PATHS true)
set(CMAKE_SUPPRESS_REGENERATION true)
set(CMAKE_MODULE_PATH "$ENV{OGRE_HOME}/CMake/;${CMAKE_MODULE_PATH}")
set(OGRE_SAMPLES_INCLUDEPATH
$ENV{OGRE_HOME}/Samples/include)
endif ()

# Assign compiler for Mac OS X-based systems
# NOTE: This logic is order-dependent and must occur here because the
@@ -25,15 +25,15 @@ endif()
# if compiler assignments are modified after issuing a project(...) command.
#
if (OGRE_BUILD_PLATFORM_IPHONE)
# Force gcc <= 4.2 on iPhone
include(CMakeForceCompiler)
CMAKE_FORCE_C_COMPILER(gcc-4.2 GNU)
CMAKE_FORCE_CXX_COMPILER(gcc-4.2 GNU)
# Force gcc <= 4.2 on iPhone
include(CMakeForceCompiler)
CMAKE_FORCE_C_COMPILER(gcc-4.2 GNU)
CMAKE_FORCE_CXX_COMPILER(gcc-4.2 GNU)
elseif (APPLE AND NOT OGRE_BUILD_PLATFORM_IPHONE)
# Force gcc <= 4.0 on Mac OS X because 4.2 is not supported prior to Mac OS X 10.5
#include(CMakeForceCompiler)
#CMAKE_FORCE_C_COMPILER(gcc-4.0 GNU)
#CMAKE_FORCE_CXX_COMPILER(gcc-4.0 GNU)
# Force gcc <= 4.0 on Mac OS X because 4.2 is not supported prior to Mac OS X 10.5
#include(CMakeForceCompiler)
#CMAKE_FORCE_C_COMPILER(gcc-4.0 GNU)
#CMAKE_FORCE_CXX_COMPILER(gcc-4.0 GNU)
endif ()

set(OGRE_PROJECT_NAME "CubeWorld")
@@ -46,21 +46,21 @@ if (APPLE)
# Include necessary submodules
set(OGRE_SOURCE_DIR "/Users/rhaamo/src/OgreSDK")
set(CMAKE_MODULE_PATH
"${OGRE_SOURCE_DIR}/CMake"
"${OGRE_SOURCE_DIR}/CMake/Utils"
"${OGRE_SOURCE_DIR}/CMake/Packages"
)
set(OGRE_SAMPLES_INCLUDEPATH "${OGRE_SOURCE_DIR}/Samples/Common/include" )
"${OGRE_SOURCE_DIR}/CMake"
"${OGRE_SOURCE_DIR}/CMake/Utils"
"${OGRE_SOURCE_DIR}/CMake/Packages"
)
set(OGRE_SAMPLES_INCLUDEPATH "${OGRE_SOURCE_DIR}/Samples/Common/include")
endif (APPLE)

if(${CMAKE_SYSTEM} MATCHES "Linux")
if (${CMAKE_SYSTEM} MATCHES "Linux")
# Include necessary submodules
set(OGRE_SOURCE_DIR "/home/dashie/hack/ogre/ogre-1.11.5")
set(CMAKE_MODULE_PATH
"${OGRE_SOURCE_DIR}/cmake/"
"${OGRE_SOURCE_DIR}/CMake/Utils/"
)
set(OGRE_SAMPLES_INCLUDEPATH "${OGRE_SOURCE_DIR}/Samples/Common/include" )
"${OGRE_SOURCE_DIR}/cmake/"
"${OGRE_SOURCE_DIR}/CMake/Utils/"
)
set(OGRE_SAMPLES_INCLUDEPATH "${OGRE_SOURCE_DIR}/Samples/Common/include")
endif (${CMAKE_SYSTEM} MATCHES "Linux")

include(CMakeDependentOption)
@@ -76,67 +76,67 @@ set(OGRE_TEMPLATES_DIR "${OGRE_SOURCE_DIR}/CMake/Templates")
#####################################################################

if (CMAKE_BUILD_TYPE STREQUAL "")
# CMake defaults to leaving CMAKE_BUILD_TYPE empty. This screws up
# differentiation between debug and release builds.
set(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING "Choose the type of build, options are: None (CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel." FORCE)
# CMake defaults to leaving CMAKE_BUILD_TYPE empty. This screws up
# differentiation between debug and release builds.
set(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING "Choose the type of build, options are: None (CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel." FORCE)
endif ()

if (NOT APPLE)
# Create debug libraries with _d postfix
set(CMAKE_DEBUG_POSTFIX "_d")
# Create debug libraries with _d postfix
set(CMAKE_DEBUG_POSTFIX "_d")
endif ()

# Set compiler specific build flags
if (CMAKE_COMPILER_IS_GNUCXX)
check_cxx_compiler_flag(-msse OGRE_GCC_HAS_SSE)
if (OGRE_GCC_HAS_SSE)
add_definitions(-msse)
endif ()
check_cxx_compiler_flag(-msse OGRE_GCC_HAS_SSE)
if (OGRE_GCC_HAS_SSE)
add_definitions(-msse)
endif ()
endif ()
if (MSVC)
if (CMAKE_BUILD_TOOL STREQUAL "nmake")
# set variable to state that we are using nmake makefiles
set(NMAKE TRUE)
endif ()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /fp:fast")
# Enable intrinsics on MSVC in debug mode
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /Oi")
if (CMAKE_CL_64)
# Visual Studio bails out on debug builds in 64bit mode unless
# this flag is set...
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /bigobj")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} /bigobj")
endif ()
if (CMAKE_BUILD_TOOL STREQUAL "nmake")
# set variable to state that we are using nmake makefiles
set(NMAKE TRUE)
endif ()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /fp:fast")
# Enable intrinsics on MSVC in debug mode
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /Oi")
if (CMAKE_CL_64)
# Visual Studio bails out on debug builds in 64bit mode unless
# this flag is set...
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /bigobj")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} /bigobj")
endif ()
endif ()
if (MINGW)
add_definitions(-D_WIN32_WINNT=0x0500)
add_definitions(-D_WIN32_WINNT=0x0500)
endif ()

if (CMAKE_COMPILER_IS_GNUCXX AND NOT MINGW)
# Test for GCC visibility
include(CheckCXXCompilerFlag)
check_cxx_compiler_flag(-fvisibility=hidden OGRE_GCC_VISIBILITY)
if (OGRE_GCC_VISIBILITY)
# determine gcc version
execute_process(COMMAND ${CMAKE_CXX_COMPILER} -dumpversion
OUTPUT_VARIABLE OGRE_GCC_VERSION)
message(STATUS "Detected g++ ${OGRE_GCC_VERSION}")
message(STATUS "Enabling GCC visibility flags")
set(OGRE_GCC_VISIBILITY_FLAGS "-DOGRE_GCC_VISIBILITY -fvisibility=hidden")

# check if we can safely add -fvisibility-inlines-hidden
string(TOLOWER "${CMAKE_BUILD_TYPE}" OGRE_BUILD_TYPE)
if (OGRE_BUILD_TYPE STREQUAL "debug" AND OGRE_GCC_VERSION VERSION_LESS "4.2")
message(STATUS "Skipping -fvisibility-inlines-hidden due to possible bug in g++ < 4.2")
else ()
set(OGRE_GCC_VISIBILITY_FLAGS "${OGRE_GCC_VISIBILITY_FLAGS} -fvisibility-inlines-hidden")
# Test for GCC visibility
include(CheckCXXCompilerFlag)
check_cxx_compiler_flag(-fvisibility=hidden OGRE_GCC_VISIBILITY)
if (OGRE_GCC_VISIBILITY)
# determine gcc version
execute_process(COMMAND ${CMAKE_CXX_COMPILER} -dumpversion
OUTPUT_VARIABLE OGRE_GCC_VERSION)
message(STATUS "Detected g++ ${OGRE_GCC_VERSION}")
message(STATUS "Enabling GCC visibility flags")
set(OGRE_GCC_VISIBILITY_FLAGS "-DOGRE_GCC_VISIBILITY -fvisibility=hidden")

# check if we can safely add -fvisibility-inlines-hidden
string(TOLOWER "${CMAKE_BUILD_TYPE}" OGRE_BUILD_TYPE)
if (OGRE_BUILD_TYPE STREQUAL "debug" AND OGRE_GCC_VERSION VERSION_LESS "4.2")
message(STATUS "Skipping -fvisibility-inlines-hidden due to possible bug in g++ < 4.2")
else ()
set(OGRE_GCC_VISIBILITY_FLAGS "${OGRE_GCC_VISIBILITY_FLAGS} -fvisibility-inlines-hidden")
endif ()
endif (OGRE_GCC_VISIBILITY)

# Fix x64 issues on Linux
if ("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64" AND NOT APPLE)
add_definitions(-fPIC)
endif ()
endif (OGRE_GCC_VISIBILITY)

# Fix x64 issues on Linux
if("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64" AND NOT APPLE)
add_definitions(-fPIC)
endif()
endif (CMAKE_COMPILER_IS_GNUCXX AND NOT MINGW)

# determine system endianess
@@ -148,14 +148,14 @@ set(OGRE_TEST_BIG_ENDIAN FALSE)
include_directories("${OGRE_SOURCE_DIR}/OgreMain/include")
include_directories("${OGRE_BINARY_DIR}/include")
if (APPLE)
if (OGRE_BUILD_PLATFORM_IPHONE)
include_directories("${OGRE_SOURCE_DIR}/OgreMain/include/iPhone")
# Set static early for proper dependency detection
set(OGRE_STATIC TRUE)
else ()
include_directories("${OGRE_SOURCE_DIR}/OgreMain/include/OSX")
endif ()
if (OGRE_BUILD_PLATFORM_IPHONE)
include_directories("${OGRE_SOURCE_DIR}/OgreMain/include/iPhone")
# Set static early for proper dependency detection
set(OGRE_STATIC TRUE)
else ()
include_directories("${OGRE_SOURCE_DIR}/OgreMain/include/OSX")
endif ()
endif (APPLE)


@@ -172,72 +172,72 @@ link_directories(${ZZ_LIBRARY_DIRS})

# Find Boost
if (NOT OGRE_BUILD_PLATFORM_IPHONE)
if (WIN32 OR APPLE)
set(Boost_USE_STATIC_LIBS TRUE)
else ()
# Statically linking boost to a dynamic Ogre build doesn't work on Linux 64bit
set(Boost_USE_STATIC_LIBS ${OGRE_STATIC})
endif ()
if (MINGW)
# this is probably a bug in CMake: the boost find module tries to look for
# boost libraries with name libboost_*, but CMake already prefixes library
# search names with "lib". This is the workaround.
set(CMAKE_FIND_LIBRARY_PREFIXES ${CMAKE_FIND_LIBRARY_PREFIXES} "")
endif ()
set(Boost_ADDITIONAL_VERSIONS "1.42" "1.42.0" "1.41.0" "1.41" "1.40.0" "1.40" "1.39.0" "1.39" "1.38.0" "1.38" "1.37.0" "1.37" )
# Components that need linking (NB does not include header-only components like bind)
set(OGRE_BOOST_COMPONENTS thread date_time)
find_package(Boost COMPONENTS ${OGRE_BOOST_COMPONENTS} QUIET)
if (NOT Boost_FOUND)
# Try again with the other type of libs
set(Boost_USE_STATIC_LIBS NOT ${Boost_USE_STATIC_LIBS})
find_package(Boost COMPONENTS ${OGRE_BOOST_COMPONENTS} QUIET)
endif()
find_package(Boost QUIET)
# Set up referencing of Boost
include_directories(${Boost_INCLUDE_DIR})
add_definitions(-DBOOST_ALL_NO_LIB)
set(OGRE_LIBRARIES ${OGRE_LIBRARIES} ${Boost_LIBRARIES})
endif()
if (WIN32 OR APPLE)
set(Boost_USE_STATIC_LIBS TRUE)
else ()
# Statically linking boost to a dynamic Ogre build doesn't work on Linux 64bit
set(Boost_USE_STATIC_LIBS ${OGRE_STATIC})
endif ()
if (MINGW)
# this is probably a bug in CMake: the boost find module tries to look for
# boost libraries with name libboost_*, but CMake already prefixes library
# search names with "lib". This is the workaround.
set(CMAKE_FIND_LIBRARY_PREFIXES ${CMAKE_FIND_LIBRARY_PREFIXES} "")
endif ()
set(Boost_ADDITIONAL_VERSIONS "1.42" "1.42.0" "1.41.0" "1.41" "1.40.0" "1.40" "1.39.0" "1.39" "1.38.0" "1.38" "1.37.0" "1.37")
# Components that need linking (NB does not include header-only components like bind)
set(OGRE_BOOST_COMPONENTS thread date_time)
find_package(Boost COMPONENTS ${OGRE_BOOST_COMPONENTS} QUIET)
if (NOT Boost_FOUND)
# Try again with the other type of libs
set(Boost_USE_STATIC_LIBS NOT ${Boost_USE_STATIC_LIBS})
find_package(Boost COMPONENTS ${OGRE_BOOST_COMPONENTS} QUIET)
endif ()
find_package(Boost QUIET)
# Set up referencing of Boost
include_directories(${Boost_INCLUDE_DIR})
add_definitions(-DBOOST_ALL_NO_LIB)
set(OGRE_LIBRARIES ${OGRE_LIBRARIES} ${Boost_LIBRARIES})
endif ()

IF (APPLE)
FIND_LIBRARY(IOKIT_LIBRARY IOKit)
FIND_LIBRARY(COREFOUNDATION_LIBRARY CoreFoundation )
FIND_LIBRARY(OGRE_LIBRARY OGRE)
LINK_DIRECTORIES(${LINK_DIRECTORIES} /opt/local/lib)
# Ogre 3D is a 32bit only SDK build ATM :(
set(CMAKE_C_FLAGS "-m32")
set(CMAKE_CXX_FLAGS "-m32")
FIND_LIBRARY(IOKIT_LIBRARY IOKit)
FIND_LIBRARY(COREFOUNDATION_LIBRARY CoreFoundation)
FIND_LIBRARY(OGRE_LIBRARY OGRE)
LINK_DIRECTORIES(${LINK_DIRECTORIES} /opt/local/lib)
# Ogre 3D is a 32bit only SDK build ATM :(
set(CMAKE_C_FLAGS "-m32")
set(CMAKE_CXX_FLAGS "-m32")
ENDIF (APPLE)

set(LIBNOISE_LIBRARIES noise)

set(HDRS
./src/BaseApplication.h
./src/CubeWorld.h
./src/noiseutils/noiseutils.h
./src/BaseApp.h
./src/CubeWorld.h
./src/noiseutils/noiseutils.h
./src/il_defs.h
./src/il_landscape.h
./src/il_map.cpp
./src/il_noiseutils.cpp
./src/compat.h
)
)

set(SRCS
./src/BaseApplication.cpp
./src/CubeWorld.cpp
./src/noiseutils/noiseutils.cpp
./src/BaseApp.cpp
./src/CubeWorld.cpp
./src/noiseutils/noiseutils.cpp
./src/il_defs.cpp
./src/il_landscape.cpp
./src/il_map.cpp
./src/il_noiseutils.cpp
)
)

include_directories( ${OIS_INCLUDE_DIRS}
${OGRE_INCLUDE_DIRS}
${OGRE_SAMPLES_INCLUDEPATH}
)
include_directories(${OIS_INCLUDE_DIRS}
${OGRE_INCLUDE_DIRS}
${OGRE_SAMPLES_INCLUDEPATH}
)


add_executable(${OGRE_PROJECT_NAME} WIN32 ${HDRS} ${SRCS})
@@ -250,54 +250,54 @@ file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/dist/bin)
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/dist/media)

# post-build copy for win32
if(WIN32 AND NOT MINGW)
add_custom_command( TARGET ${OGRE_PROJECT_NAME} PRE_BUILD
COMMAND if not exist .\\dist\\bin mkdir .\\dist\\bin )
add_custom_command( TARGET ${OGRE_PROJECT_NAME} POST_BUILD
COMMAND copy \"$(TargetPath)\" .\\dist\\bin )
endif(WIN32 AND NOT MINGW)
if(MINGW)
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/dist/bin)
endif(MINGW)
if(WIN32)
install(TARGETS ${OGRE_PROJECT_NAME}
RUNTIME DESTINATION bin
CONFIGURATIONS All)
install(DIRECTORY ${CMAKE_SOURCE_DIR}/dist/Media
DESTINATION ./
CONFIGURATIONS Release RelWithDebInfo Debug
)
install(FILES ${CMAKE_SOURCE_DIR}/dist/bin/plugins.cfg
${CMAKE_SOURCE_DIR}/dist/bin/resources.cfg
DESTINATION bin
CONFIGURATIONS Release RelWithDebInfo
)
install(FILES ${CMAKE_SOURCE_DIR}/dist/bin/plugins_d.cfg
${CMAKE_SOURCE_DIR}/dist/bin/resources_d.cfg
DESTINATION bin
CONFIGURATIONS Debug
)
install(FILES ${OGRE_PLUGIN_DIR_REL}/OgreMain.dll
${OGRE_PLUGIN_DIR_REL}/RenderSystem_Direct3D9.dll
${OGRE_PLUGIN_DIR_REL}/RenderSystem_GL.dll
${OGRE_PLUGIN_DIR_REL}/OIS.dll
DESTINATION bin
CONFIGURATIONS Release RelWithDebInfo
)
install(FILES ${OGRE_PLUGIN_DIR_DBG}/OgreMain_d.dll
${OGRE_PLUGIN_DIR_DBG}/RenderSystem_Direct3D9_d.dll
${OGRE_PLUGIN_DIR_DBG}/RenderSystem_GL_d.dll
${OGRE_PLUGIN_DIR_DBG}/OIS_d.dll
DESTINATION bin
CONFIGURATIONS Debug
)
endif(WIN32)
if (WIN32 AND NOT MINGW)
add_custom_command(TARGET ${OGRE_PROJECT_NAME} PRE_BUILD
COMMAND if not exist .\\dist\\bin mkdir .\\dist\\bin)
add_custom_command(TARGET ${OGRE_PROJECT_NAME} POST_BUILD
COMMAND copy \"$(TargetPath)\" .\\dist\\bin)
endif (WIN32 AND NOT MINGW)
if (MINGW)
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/dist/bin)
endif (MINGW)
if (WIN32)
install(TARGETS ${OGRE_PROJECT_NAME}
RUNTIME DESTINATION bin
CONFIGURATIONS All)
install(DIRECTORY ${CMAKE_SOURCE_DIR}/dist/Media
DESTINATION ./
CONFIGURATIONS Release RelWithDebInfo Debug
)
install(FILES ${CMAKE_SOURCE_DIR}/dist/bin/plugins.cfg
${CMAKE_SOURCE_DIR}/dist/bin/resources.cfg
DESTINATION bin
CONFIGURATIONS Release RelWithDebInfo
)
install(FILES ${CMAKE_SOURCE_DIR}/dist/bin/plugins_d.cfg
${CMAKE_SOURCE_DIR}/dist/bin/resources_d.cfg
DESTINATION bin
CONFIGURATIONS Debug
)
install(FILES ${OGRE_PLUGIN_DIR_REL}/OgreMain.dll
${OGRE_PLUGIN_DIR_REL}/RenderSystem_Direct3D9.dll
${OGRE_PLUGIN_DIR_REL}/RenderSystem_GL.dll
${OGRE_PLUGIN_DIR_REL}/OIS.dll
DESTINATION bin
CONFIGURATIONS Release RelWithDebInfo
)
install(FILES ${OGRE_PLUGIN_DIR_DBG}/OgreMain_d.dll
${OGRE_PLUGIN_DIR_DBG}/RenderSystem_Direct3D9_d.dll
${OGRE_PLUGIN_DIR_DBG}/RenderSystem_GL_d.dll
${OGRE_PLUGIN_DIR_DBG}/OIS_d.dll
DESTINATION bin
CONFIGURATIONS Debug
)
endif (WIN32)

set_property(TARGET ${OGRE_PROJECT_NAME} PROPERTY MACOSX_BUNDLE TRUE)

+ 187
- 0
src/BaseApp.cpp View File

@@ -0,0 +1,187 @@
#include "BaseApp.h"

BaseApp::BaseApp()
: ApplicationContext("CubeWorldApp")
{
}

BaseApp::~BaseApp(void) {
if (trayMgr) delete trayMgr;

//Remove ourself as a Window listener
windowClosed(getRenderWindow());
delete root;
}

void BaseApp::setup()
{
// do not forget to call the base first
ApplicationContext::setup();
addInputListener(this);

// - Create a Scene
// get a pointer to the already created root
root = getRoot();
scnMgr = root->createSceneManager();

// register our scene with the RTSS
RTShader::ShaderGenerator* shadergen = RTShader::ShaderGenerator::getSingletonPtr();
shadergen->addSceneManager(scnMgr);

// - Create a Camera
//! [camera]
SceneNode* camNode = scnMgr->getRootSceneNode()->createChildSceneNode();
cam = scnMgr->createCamera("myCam");

// Position it at 500 in Z direction
camNode->setPosition(Vector3(-31,140,202));
// Look back along -Z
camNode->lookAt(Vector3(0.084, -0.6, 0.05), Node::TransformSpace::TS_WORLD);
cam->setNearClipDistance(5);
camNode->attachObject(cam);

// - Create viewports
// Create one viewport, entire window
Viewport *vp = getRenderWindow()->addViewport(cam);

vp->setBackgroundColour(ColourValue(0,0,0));

// Alter the camera aspect ratio to match the viewport
cam->setAspectRatio(Real(vp->getActualWidth()) / Real(vp->getActualHeight()));

// - Set default mipmap level (NB some APIs ignore this)
TextureManager::getSingleton().setDefaultNumMipmaps(5);

// - CubeWorld create scene
createScene(); // reside in CubeWorld.cpp, full scene init

// - Tray manager thing

trayMgr = new TrayManager("InterfaceName", getRenderWindow());
trayMgr->showFrameStats(OgreBites::TL_BOTTOMLEFT);
trayMgr->showLogo(OgreBites::TL_BOTTOMRIGHT);
trayMgr->toggleAdvancedFrameStats();
trayMgr->showCursor();

// Create a panel to display sample details
StringVector items;
items.push_back("cam.pX");
items.push_back("cam.pY");
items.push_back("cam.pZ");
items.push_back("");
items.push_back("cam.oW");
items.push_back("cam.oX");
items.push_back("cam.oY");
items.push_back("cam.oZ");
items.push_back("");
items.push_back("Filtering");
items.push_back("Poly Mode");

detailsPanel = trayMgr->createParamsPanel(TL_NONE, "DetailsPanel", 200, items);
detailsPanel->setParamValue(9, "Bilinear");
detailsPanel->setParamValue(10, "Solid");
detailsPanel->show();

addInputListener(trayMgr); // relay inputs to the tray manager

//getRoot()->addFrameListener(this);
}


bool BaseApp::keyPressed(const KeyboardEvent& evt)
{

LogManager::getSingletonPtr()->logMessage("pwessed a key");

switch (evt.keysym.sym) {
case SDLK_ESCAPE:
getRoot()->queueEndRendering();
break;
case 'f':
trayMgr->toggleAdvancedFrameStats();
break;
case 'g':
if (detailsPanel->getTrayLocation() == TL_NONE) {
trayMgr->moveWidgetToTray(detailsPanel, TL_TOPRIGHT, 0);
detailsPanel->show();
} else {
trayMgr->removeWidgetFromTray(detailsPanel);
detailsPanel->hide();
}
break;
case 't': {
String newVal;
TextureFilterOptions tfo;
unsigned int aniso;

switch (detailsPanel->getParamValue(9).asUTF8()[0]) {
case 'B':
newVal = "Trilinear";
tfo = Ogre::TFO_TRILINEAR;
aniso = 1;
break;
case 'T':
newVal = "Anisotropic";
tfo = Ogre::TFO_ANISOTROPIC;
aniso = 8;
break;
case 'A':
newVal = "None";
tfo = Ogre::TFO_NONE;
aniso = 1;
break;
default:
newVal = "Bilinear";
tfo = Ogre::TFO_BILINEAR;
aniso = 1;
}

MaterialManager::getSingleton().setDefaultTextureFiltering(tfo);
MaterialManager::getSingleton().setDefaultAnisotropy(aniso);
detailsPanel->setParamValue(9, newVal);
break;
}
case 'r': {
String newValPol;
PolygonMode pm;
switch (cam->getPolygonMode()) {
case Ogre::PM_SOLID:
newValPol = "Wireframe";
pm = Ogre::PM_WIREFRAME;
break;
case Ogre::PM_WIREFRAME:
newValPol = "Points";
pm = Ogre::PM_POINTS;
break;
default:
newValPol = "Solid";
pm = Ogre::PM_SOLID;
}

cam->setPolygonMode(pm);
detailsPanel->setParamValue(10, newValPol);
break;
}
case SDLK_F5:
TextureManager::getSingleton().reloadAll();
break;
case 'n':
//getRenderWindow()->writeContentsToTimestampedFile("screenshot", ".jpg");
getRenderWindow()->writeContentsToTimestampedFile("screenshot", ".png");
}

return true;
}

// lol mouse don't work
bool BaseApp::mouseMoved(const MouseMotionEvent& evt) {
trayMgr->mouseMoved(evt);
return true;
}

bool BaseApp::mousePressed(const MouseButtonEvent& evt) {
trayMgr->mousePressed(evt);
return true;
}

//! [fullsource]

+ 38
- 0
src/BaseApp.h View File

@@ -0,0 +1,38 @@
#ifndef __BaseApp_h_
#define __BaseApp_h_

#include "Ogre.h"
#include "OgreApplicationContext.h"
#include "OgreInput.h"
#include "OgreRTShaderSystem.h"
#include "OgreApplicationContext.h"
#include <iostream>
#include <Bites/OgreTrays.h>

using namespace Ogre;
using namespace OgreBites;

class BaseApp
: public ApplicationContext
, public InputListener
{
public:
BaseApp();
virtual ~BaseApp();

void setup();
bool keyPressed(const KeyboardEvent& evt);
bool mouseMoved(const MouseMotionEvent& evt);
bool mousePressed(const MouseButtonEvent& evt);

protected:
virtual void createScene(void) = 0; // Override me!

TrayManager *trayMgr;
ParamsPanel *detailsPanel;
Camera *cam;
Root *root;
SceneManager *scnMgr;
};

#endif // #ifndef __BaseApp_h_

+ 1009
- 863
src/CubeWorld.cpp
File diff suppressed because it is too large
View File


+ 101
- 92
src/CubeWorld.h View File

@@ -6,7 +6,7 @@ Filename: CubeWorld.h
#ifndef __CubeWorld_h_
#define __CubeWorld_h_

#include "BaseApplication.h"
#include "BaseApp.h"
#include "compat.h"
#include "il_map.h"
#include "il_landscape.h"
@@ -14,108 +14,117 @@ Filename: CubeWorld.h
typedef unsigned char block_t;
typedef unsigned char blocklight_t;

struct blockinfo_t
{
block_t ID;
TCHAR Name[64];
TCHAR Texture[64];
bool Transparent;
struct blockinfo_t {
block_t ID;
TCHAR Name[64];
TCHAR Texture[64];
bool Transparent;
};
struct layer_t
{
block_t BlockID;
int MinLevel;
int MaxLevel;
int SeedOffset;
struct layer_t {
block_t BlockID;
int MinLevel;
int MaxLevel;
int SeedOffset;
};


blockinfo_t g_BlockInfo[] =
{
{ 0, "Air", "", true },
{ 1, "Grass", "minecraft/terrain-grass.png", false },
{ 2, "Soil", "minecraft/terrain-graveldark.png", false },
{ 3, "Rock", "minecraft/terrain-stone.png", false },
{ 4, "Lava", "minecraft/pumpkinface-blank.png", false },
{ 5, "Water", "minecraft/terrain-water.png", true },
{ 255, "null", "" } // Must be last
};
{
{0, "Air", "", true},
{1, "Grass", "minecraft/terrain-grass.png", false},
{2, "Soil", "minecraft/terrain-graveldark.png", false},
{3, "Rock", "minecraft/terrain-stone.png", false},
{4, "Lava", "minecraft/pumpkinface-blank.png", false},
{5, "Water", "minecraft/terrain-water.png", true},
{255, "null", ""} // Must be last
};
layer_t g_Layers[] =
{
{ 5, 0, 2, 5 }, // Water
{ 1, 0, 2, 1 }, // Grass
{ 2, 0, 10, 2 }, // Soil
{ 3, 20, 200, 3 }, // Rock
{ 4, 100, 300, 4 }, // Lava
{ 255, 0, 0, 0 } // Must be last
};

class CubeWorld : public BaseApplication
{
{
{5, 0, 2, 5}, // Water
{1, 0, 2, 1}, // Grass
{2, 0, 10, 2}, // Soil
{3, 20, 200, 3}, // Rock
{4, 100, 300, 4}, // Lava
{255, 0, 0, 0} // Must be last
};

class CubeWorld : public BaseApp {
public:
CubeWorld(void);
virtual ~CubeWorld(void);
CubeWorld(void);

virtual ~CubeWorld(void);

infland::CLandscape m_Landscape;
blocklight_t* m_BlockLight;
infland::CLandscape m_Landscape;
blocklight_t *m_BlockLight;

block_t& GetBlockLight (const int x, const int y, const int z)
{
return m_BlockLight[x + y * WORLD_SIZE + z * WORLD_SIZE2];
}
block_t &GetBlockLight(const int x, const int y, const int z) {
return m_BlockLight[x + y * WORLD_SIZE + z * WORLD_SIZE2];
}

private:
Ogre::ManualObject* createCubeMesh(Ogre::String name, Ogre::String matName);
static const int WORLD_SIZE = 256; // We'll change these later for various test worlds
static const int WORLD_SIZE2 = WORLD_SIZE * WORLD_SIZE;
static const int WORLD_SIZE3 = WORLD_SIZE * WORLD_SIZE * WORLD_SIZE;
static const int CHUNK_SIZE = 256;
static const int BLOCK_NULL = 255;

int m_ChunkID; // Used for uniquely naming our chunks

block_t* m_Blocks; // Holds the block worlds in a [WORLD_SIZE][WORLD_SIZE][WORLD_SIZE] array

// Read/write access method for our block world (doesn't check input)
block_t& GetBlock (const int x, const int y, const int z)
{
return m_Blocks[x + y * WORLD_SIZE + z * WORLD_SIZE * WORLD_SIZE];
}

// Used for filling our block world
void initWorldBlocksRandom (const int Divisor);
void initWorldBlocksSphere (void);
void initWorldBlocksLand ();
void initWorldBlocksLandRnd ();
void initWorldBlocksLayers ();
void initWorldBlocksCaves ();
void initWorldBlocksLight ();

// Displays the world using our original "naive" method
void displaySimpleWorld (void);

void createChunk (Ogre::ManualObject* MeshChunk, const int StartX, const int StartY, const int StartZ);
void createChunkWFaces (const int StartX, const int StartY, const int StartZ);
void createChunkWater (const int StartX, const int StartY, const int StartZ);
void createWorldChunks (void);

void createSolidTexture(const TCHAR* pName);
void createTexture(const TCHAR* pName, const TCHAR* pImageFilename);
void createWaterTexture(const TCHAR* pName);
void createSkyTexture(const TCHAR* pName);
void updateSkyTextureLight(void);


blockinfo_t GetBlockMaterial (block_t block)
{
return g_BlockInfo[block];
}

Ogre::MaterialPtr m_SkyMaterial;
Ogre::ColourValue m_LightColor;
Ogre::ColourValue m_AmbientColor;
Ogre::ColourValue m_FogColor;
float m_LightAngle;
Ogre::ManualObject *createCubeMesh(Ogre::String name, Ogre::String matName);

static const int WORLD_SIZE = 256; // We'll change these later for various test worlds
static const int WORLD_SIZE2 = WORLD_SIZE * WORLD_SIZE;
static const int WORLD_SIZE3 = WORLD_SIZE * WORLD_SIZE * WORLD_SIZE;
static const int CHUNK_SIZE = 256;
static const int BLOCK_NULL = 255;

int m_ChunkID; // Used for uniquely naming our chunks

block_t *m_Blocks; // Holds the block worlds in a [WORLD_SIZE][WORLD_SIZE][WORLD_SIZE] array

// Read/write access method for our block world (doesn't check input)
block_t &GetBlock(const int x, const int y, const int z) {
return m_Blocks[x + y * WORLD_SIZE + z * WORLD_SIZE * WORLD_SIZE];
}

// Used for filling our block world
void initWorldBlocksRandom(const int Divisor);

void initWorldBlocksSphere(void);

void initWorldBlocksLand();

void initWorldBlocksLandRnd();

void initWorldBlocksLayers();

void initWorldBlocksCaves();

void initWorldBlocksLight();

// Displays the world using our original "naive" method
void displaySimpleWorld(void);

void createChunk(Ogre::ManualObject *MeshChunk, const int StartX, const int StartY, const int StartZ);

void createChunkWFaces(const int StartX, const int StartY, const int StartZ);

void createChunkWater(const int StartX, const int StartY, const int StartZ);

void createWorldChunks(void);

void createSolidTexture(const TCHAR *pName);

void createTexture(const TCHAR *pName, const TCHAR *pImageFilename);

void createWaterTexture(const TCHAR *pName);

void createSkyTexture(const TCHAR *pName);

void updateSkyTextureLight(void);


blockinfo_t GetBlockMaterial(block_t block) {
return g_BlockInfo[block];
}

Ogre::MaterialPtr m_SkyMaterial;
Ogre::ColourValue m_LightColor;
Ogre::ColourValue m_AmbientColor;
Ogre::ColourValue m_FogColor;
float m_LightAngle;

protected:
virtual void createScene(void);


src/BaseApplication.cpp → src/old/BaseApplication.cpp View File

@@ -39,7 +39,6 @@ BaseApplication::BaseApplication(void)
BaseApplication::~BaseApplication(void)
{
if (mTrayMgr) delete mTrayMgr;
if (mCameraMan) delete mCameraMan;

//Remove ourself as a Window listener
OgreBites::WindowEventUtilities::removeWindowEventListener(mWindow, this);
@@ -66,122 +65,12 @@ bool BaseApplication::configure(void)
return false;
}
}
//-------------------------------------------------------------------------------------
void BaseApplication::chooseSceneManager(void)
{
// Get the SceneManager, in this case a generic one
// Deprecated
//mSceneMgr = mRoot->createSceneManager(Ogre::ST_GENERIC);
mSceneMgr = mRoot->createSceneManager();
}
//-------------------------------------------------------------------------------------
void BaseApplication::createCamera(void)
{
// Create the camera
mCamera = mSceneMgr->createCamera("PlayerCam");

mCameraNode = mSceneMgr->getRootSceneNode();

// Position it at 500 in Z direction
mCameraNode->setPosition(Ogre::Vector3(-31,140,202));
// Look back along -Z
mCameraNode->lookAt(Ogre::Vector3(0.084, -0.6, 0.05), Ogre::Node::TS_PARENT);
mCamera->setNearClipDistance(5);

mCameraMan = new OgreBites::CameraMan(mCameraNode); // create a default camera controller
}
//-------------------------------------------------------------------------------------
void BaseApplication::createFrameListener(void)
{
Ogre::LogManager::getSingletonPtr()->logMessage("*** Initializing OIS ***");
OIS::ParamList pl;
size_t windowHnd = 0;
std::ostringstream windowHndStr;

mWindow->getCustomAttribute("WINDOW", &windowHnd);
windowHndStr << windowHnd;
pl.insert(std::make_pair(std::string("WINDOW"), windowHndStr.str()));

mInputManager = OIS::InputManager::createInputSystem( pl );

mKeyboard = static_cast<OIS::Keyboard*>(mInputManager->createInputObject( OIS::OISKeyboard, true ));
mMouse = static_cast<OIS::Mouse*>(mInputManager->createInputObject( OIS::OISMouse, true ));

mMouse->setEventCallback(this);
mKeyboard->setEventCallback(this);

//Set initial mouse clipping size
windowResized(mWindow);

//Register as a Window listener
Ogre::WindowEventUtilities::addWindowEventListener(mWindow, this);

mTrayMgr = new OgreBites::TrayManager("InterfaceName", mWindow, this);
mTrayMgr->showFrameStats(OgreBites::TL_BOTTOMLEFT);
mTrayMgr->showLogo(OgreBites::TL_BOTTOMRIGHT);
mTrayMgr->hideCursor();

// create a params panel for displaying sample details
Ogre::StringVector items;
items.push_back("cam.pX");
items.push_back("cam.pY");
items.push_back("cam.pZ");
items.push_back("");
items.push_back("cam.oW");
items.push_back("cam.oX");
items.push_back("cam.oY");
items.push_back("cam.oZ");
items.push_back("");
items.push_back("Filtering");
items.push_back("Poly Mode");

mDetailsPanel = mTrayMgr->createParamsPanel(OgreBites::TL_NONE, "DetailsPanel", 200, items);
mDetailsPanel->setParamValue(9, "Bilinear");
mDetailsPanel->setParamValue(10, "Solid");
mDetailsPanel->hide();

mRoot->addFrameListener(this);
}
//-------------------------------------------------------------------------------------
void BaseApplication::destroyScene(void)
{
}
//-------------------------------------------------------------------------------------
void BaseApplication::createViewports(void)
{
// Create one viewport, entire window
Ogre::Viewport* vp = mWindow->addViewport(mCamera);
vp->setBackgroundColour(Ogre::ColourValue(0,0,0));

// Alter the camera aspect ratio to match the viewport
mCamera->setAspectRatio(
Ogre::Real(vp->getActualWidth()) / Ogre::Real(vp->getActualHeight()));
}
//-------------------------------------------------------------------------------------
void BaseApplication::setupResources(void)
{
// Load resource paths from config file
Ogre::ConfigFile cf;
cf.load(mResourcesCfg);

// Go through all sections & settings in the file
Ogre::ConfigFile::SectionIterator seci = cf.getSectionIterator();

Ogre::String secName, typeName, archName;
while (seci.hasMoreElements())
{
secName = seci.peekNextKey();
Ogre::ConfigFile::SettingsMultiMap *settings = seci.getNext();
Ogre::ConfigFile::SettingsMultiMap::iterator i;
for (i = settings->begin(); i != settings->end(); ++i)
{
typeName = i->first;
archName = i->second;
Ogre::ResourceGroupManager::getSingleton().addResourceLocation(
archName, typeName, secName);
}
}
}
//-------------------------------------------------------------------------------------
void BaseApplication::createResourceListener(void)
{
@@ -193,53 +82,8 @@ void BaseApplication::loadResources(void)
Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
}
//-------------------------------------------------------------------------------------
void BaseApplication::go(void)
{
#ifdef _DEBUG
mResourcesCfg = "resources_d.cfg";
mPluginsCfg = "plugins_d.cfg";
#else
mResourcesCfg = "resources.cfg";
mPluginsCfg = "plugins.cfg";
#endif

if (!setup())
return;

mRoot->startRendering();

// clean up
destroyScene();
}
//-------------------------------------------------------------------------------------
bool BaseApplication::setup(void)
{
mRoot = new Ogre::Root(mPluginsCfg);

setupResources();

bool carryOn = configure();
if (!carryOn) return false;

chooseSceneManager();
createCamera();
createViewports();

// Set default mipmap level (NB some APIs ignore this)
Ogre::TextureManager::getSingleton().setDefaultNumMipmaps(5);

// Create any resource listeners (for loading screens)
createResourceListener();
// Load resources
loadResources();

// Create the scene
createScene();

createFrameListener();

return true;
};
//-------------------------------------------------------------------------------------
bool BaseApplication::frameRenderingQueued(const Ogre::FrameEvent& evt)
{
@@ -255,11 +99,13 @@ bool BaseApplication::frameRenderingQueued(const Ogre::FrameEvent& evt)

// TODO FIXME this thing
//mTrayMgr->frameRenderingQueued(evt);
mTrayMgr->frameRendered(evt);

if (!mTrayMgr->isDialogVisible())
{
// this one too FIXME TODO
//mCameraMan->frameRenderingQueued(evt); // if dialog isn't up, then update the camera
mCameraMan->frameRendered(evt);
if (mDetailsPanel->isVisible()) // if details panel is visible, then update its contents
{
mDetailsPanel->setParamValue(0, Ogre::StringConverter::toString(mCamera->getDerivedPosition().x));

src/BaseApplication.h → src/old/BaseApplication.h View File

@@ -42,7 +42,7 @@ This source file is part of the

#include <iostream>

class BaseApplication : public Ogre::FrameListener, public Ogre::WindowEventListener, public OIS::KeyListener, public OIS::MouseListener, OgreBites::TrayListener
class BaseApplication : public OgreBites::ApplicationContext, public Ogre::WindowEventListener, public OIS::KeyListener, public OIS::MouseListener, OgreBites::TrayListener
{
public:
BaseApplication(void);
@@ -51,7 +51,7 @@ public:
virtual void go(void);

protected:
virtual bool setup();
virtual void setup();
virtual bool configure(void);
virtual void chooseSceneManager(void);
virtual void createCamera(void);

Loading…
Cancel
Save