summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDidier Raboud <odyx@debian.org>2013-01-08 08:30:30 +0100
committerDidier Raboud <odyx@debian.org>2013-01-08 08:53:35 +0100
commitbcb1b7ca230c7c7be3fc7be152187b95cbe64942 (patch)
treecbab7dcf3829ded833a7e312258cf3a8859da292
parentb558ec169acf8f0ff6f2a06ebf54c44b039db80b (diff)
parent5a6b3f005a83363d323e00b499756d6ecc277574 (diff)
downloadcolobot-bcb1b7ca230c7c7be3fc7be152187b95cbe64942.tar.gz
colobot-bcb1b7ca230c7c7be3fc7be152187b95cbe64942.tar.bz2
colobot-bcb1b7ca230c7c7be3fc7be152187b95cbe64942.zip
Merge branch 'dev' into debian
-rw-r--r--CMakeLists.txt50
-rw-r--r--README.md (renamed from README.txt)48
-rw-r--r--debian/changelog2
-rw-r--r--debian/control1
-rw-r--r--src/CBot/tests/CBot_console/CMakeLists.txt1
-rw-r--r--src/CMakeLists.txt46
-rw-r--r--src/app/app.cpp131
-rw-r--r--src/app/app.h52
-rw-r--r--src/common/config.h.cmake1
-rw-r--r--src/common/image.cpp9
-rw-r--r--src/common/image.h3
-rw-r--r--src/common/test/CMakeLists.txt1
-rw-r--r--src/desktop/colobot.desktop.in1
-rw-r--r--src/graphics/core/device.h60
-rw-r--r--src/graphics/core/vertex.h20
-rw-r--r--src/graphics/engine/engine.cpp2273
-rw-r--r--src/graphics/engine/engine.h361
-rw-r--r--src/graphics/engine/modelfile.cpp137
-rw-r--r--src/graphics/engine/modelfile.h27
-rw-r--r--src/graphics/engine/modelmanager.cpp213
-rw-r--r--src/graphics/engine/modelmanager.h97
-rw-r--r--src/graphics/engine/particle.cpp2
-rw-r--r--src/graphics/engine/terrain.cpp27
-rw-r--r--src/graphics/engine/terrain.h2
-rw-r--r--src/graphics/engine/test/CMakeLists.txt2
-rw-r--r--src/graphics/engine/test/modelfile_test.cpp12
-rw-r--r--src/graphics/engine/text.cpp10
-rw-r--r--src/graphics/engine/water.cpp6
-rw-r--r--src/graphics/opengl/gldevice.cpp543
-rw-r--r--src/graphics/opengl/gldevice.h43
-rw-r--r--src/graphics/opengl/test/CMakeLists.txt1
-rw-r--r--src/graphics/opengl/test/light_test.cpp27
-rw-r--r--src/graphics/opengl/test/texture_test.cpp1
-rw-r--r--src/math/intpoint.h6
-rw-r--r--src/math/test/CMakeLists.txt1
-rw-r--r--src/object/motion/motionant.cpp123
-rw-r--r--src/object/motion/motionbee.cpp83
-rw-r--r--src/object/motion/motionhuman.cpp120
-rw-r--r--src/object/motion/motionmother.cpp74
-rw-r--r--src/object/motion/motionspider.cpp36
-rw-r--r--src/object/motion/motiontoto.cpp39
-rw-r--r--src/object/motion/motionvehicle.cpp482
-rw-r--r--src/object/motion/motionworm.cpp20
-rw-r--r--src/object/object.cpp698
-rw-r--r--src/object/robotmain.cpp4
-rw-r--r--src/script/script.cpp6
-rw-r--r--src/sound/oalsound/alsound.cpp32
-rw-r--r--src/sound/oalsound/channel.cpp59
-rw-r--r--src/sound/oalsound/channel.h1
-rw-r--r--src/sound/sound.h3
-rw-r--r--src/tools/CMakeLists.txt1
-rw-r--r--src/tools/convert_model.cpp21
-rw-r--r--src/ui/edit.cpp60
-rw-r--r--src/ui/edit.h2
-rw-r--r--src/ui/test/CMakeLists.txt1
-rw-r--r--tools/blender-scripts.py11
56 files changed, 3386 insertions, 2707 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index a3bd7f4..339e633 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -20,14 +20,14 @@ set(COLOBOT_VERSION_UNRELEASED "~pre-alpha")
# Append git characteristics to version
if(DEFINED COLOBOT_VERSION_UNRELEASED AND EXISTS "${CMAKE_SOURCE_DIR}/.git")
- find_package(Git)
- execute_process(COMMAND ${GIT_EXECUTABLE} rev-parse --abbrev-ref HEAD
- OUTPUT_VARIABLE GIT_BRANCH
- OUTPUT_STRIP_TRAILING_WHITESPACE)
- execute_process(COMMAND ${GIT_EXECUTABLE} rev-parse --short HEAD
- OUTPUT_VARIABLE GIT_REVISION
- OUTPUT_STRIP_TRAILING_WHITESPACE)
- set(COLOBOT_VERSION_UNRELEASED "${COLOBOT_VERSION_UNRELEASED}-git-${GIT_BRANCH}~r${GIT_REVISION}")
+ find_package(Git)
+ execute_process(COMMAND ${GIT_EXECUTABLE} rev-parse --abbrev-ref HEAD
+ OUTPUT_VARIABLE GIT_BRANCH
+ OUTPUT_STRIP_TRAILING_WHITESPACE)
+ execute_process(COMMAND ${GIT_EXECUTABLE} rev-parse --short HEAD
+ OUTPUT_VARIABLE GIT_REVISION
+ OUTPUT_STRIP_TRAILING_WHITESPACE)
+ set(COLOBOT_VERSION_UNRELEASED "${COLOBOT_VERSION_UNRELEASED}-git-${GIT_BRANCH}~r${GIT_REVISION}")
endif()
set(COLOBOT_VERSION_FULL "${COLOBOT_VERSION_MAJOR}.${COLOBOT_VERSION_MINOR}.${COLOBOT_VERSION_REVISION}${COLOBOT_VERSION_UNRELEASED}")
@@ -48,7 +48,7 @@ endif()
# Global compile flags
# These are specific to GCC/MinGW; for other compilers, change as necessary
-set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wold-style-cast -std=gnu++0x")
+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wold-style-cast -std=c++11")
set(CMAKE_CXX_FLAGS_RELEASE "-O2")
set(CMAKE_CXX_FLAGS_DEBUG "-g -O0")
@@ -67,6 +67,7 @@ option(INSTALL_DOCS "Install Doxygen-generated documentation" OFF)
# Build openal sound support
option(OPENAL_SOUND "Build openal sound support" OFF)
+
##
# Required packages
##
@@ -85,17 +86,11 @@ set(Boost_USE_STATIC_RUNTIME OFF)
set(Boost_ADDITIONALVERSION "1.51" "1.51.0")
find_package(Boost COMPONENTS system filesystem regex REQUIRED)
-# GLEW requirement depends on platform
-# By default it is auto detected
-# This setting may be used to override
-# Possible values:
-# - auto -> determine automatically
-# - 1 -> always enable
-# - 0 -> always disable
-set(USE_GLEW auto)
# This is useful on Windows, if linking against standard GLEW dll fails
option(GLEW_STATIC "Link statically with GLEW" OFF)
+find_package(GLEW REQUIRED)
+
##
# Additional settings to use when cross-compiling with MXE (http://mxe.cc/)
@@ -113,38 +108,19 @@ if (${CMAKE_SYSTEM_NAME} MATCHES "Windows")
set(PLATFORM_WINDOWS 1)
set(PLATFORM_LINUX 0)
set(PLATFORM_OTHER 0)
-
- # On Windows, GLEW is required
- if (${USE_GLEW} MATCHES "auto")
- set(USE_GLEW 1)
- endif()
elseif(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
message(STATUS "Linux system detected")
set(PLATFORM_WINDOWS 0)
set(PLATFORM_LINUX 1)
set(PLATFORM_OTHER 0)
-
- # On Linux, we should be fine without GLEW
- if (${USE_GLEW} MATCHES "auto")
- set(USE_GLEW 0)
- endif()
else()
message(STATUS "Other system detected")
set(PLATFORM_WINDOWS 0)
set(PLATFORM_LINUX 0)
set(PLATFORM_OTHER 1)
-
- # Use GLEW to be safe
- if (${USE_GLEW} MATCHES "auto")
- set(USE_GLEW 1)
- endif()
endif()
-if(${USE_GLEW})
- find_package(GLEW REQUIRED)
-endif()
-
if(NOT ${ASSERTS})
add_definitions(-DNDEBUG)
endif()
@@ -153,7 +129,7 @@ if(${TESTS})
add_definitions(-DTEST_VIRTUAL=virtual)
enable_testing()
else()
- add_definitions(-DTEST_VIRTUAL)
+ add_definitions(-DTEST_VIRTUAL=)
endif()
diff --git a/README.txt b/README.md
index 64b5a14..994fce1 100644
--- a/README.txt
+++ b/README.md
@@ -1,87 +1,91 @@
-EN
+# English
-Welcome to Colobot project repository
+Welcome to the Colobot project code repository
-NOTE: this is the new repository which was moved here from https://github.com/adiblol/colobot. The new repository has been purged of binary files cluttering the history, so all commits have been overwritten. If you have been using the old repository, you have to clone from scratch the new one.
+> NOTE: this is the new repository which was moved here from https://github.com/adiblol/colobot. The new repository has been purged of binary files cluttering the history, so all commits have been overwritten. If you have been using the old repository, you have to clone from scratch the new one.
This is official repository for the open-source Colobot project developed by Polish Portal of Colobot (PPC; in Polish: Polski Portal Colobota) with the official site at: http://colobot.info/.
The source code contained here was released by Epsitec -- the original creator of the game -- on open source (GPLv3) license. The code was given and the rights granted specifically to PPC community in March 2012. Since then, we have been modifying the code and working on our goals, which are briefly summed up below.
-More information for developers (in English) can be found at developer wiki at: https://colobot.info/wiki/Dev:Main_Page. However, the freshest source of information is our IRC channel #colobot at pirc.pl.
+More information for developers (in English) can be found on the [developer wiki](https://colobot.info/wiki/Dev:Main_Page). However, the freshest source of information is our IRC channels, see below.
This repository contains only the source code of the project. The game requires also data files which are available in separate packages, currently at http://colobot.info/files/. The packages are named colobot-data-YYYY-MM-DD.zip. Make sure you have the latest package before compiling and running the code in repository.
-Status
+## Status
Our main goals can be summed up in three milestones:
-Milestone 1 - Colobot Classic
+### Milestone 1 - Colobot Classic
This is the original version of the game, as released to us by Epsitec with only minor changes and bugfixes. It is available as a tag named colobot-original in the repository. This version will not be developed further. The compiled version and data packs needed to run the game (split by language version) can also be found at http://colobot.info/files/.
-Milestone 2 - Colobot Gold
+### Milestone 2 - Colobot Gold
This is a version of the game that is currently being developed in this repository. It is based on the original code, but refreshed and rewritten using SDL and OpenGL libraries, thus making it multiplatform.
-As of September 2012, we have rewritten almost all of the original code and we are in the process of testing and fixing issues that are still present in the game. The game runs and compiles under Windows and Linux. The master branch contains the current snapshot code which should always compile and run with the latest data pack. The dev branch and dev-* sub-branches are used for general development.
+As of September 2012, we have rewritten almost all of the original code and we are in the process of testing and fixing issues that are still present in the game. The game runs and compiles under Windows and Linux. The master branch contains the current snapshot code which should always compile and run with the latest data pack. The dev branch and dev-\* sub-branches are used for general development.
-Milestone 3 - Colobot 2
+### Milestone 3 - Colobot 2
This will be a new installment in the Colobot series. We have many ideas for the new game and we are still discussing them. Generally, the development of this version will begin only after finishing Colobot Gold (it will be probably hosted in another repository, forked off the Colobot Gold code).
-Compiling and running the game
+## Compiling and running the game
For these instructions see HOWTO.txt file.
-Contact
+## Contact
-If you want to help in the project, please contact us on our IRC channel #colobot at pirc.pl (Polish or English) or the forum on our website: http://colobot.info/forum (Polish only). We're in the process of moving to a new site and forum so not all information on our old site is up-to-date, but we're be done soon.
+If you want to help in the project, please contact us on our IRC channels or the forum on our website: http://colobot.info/forum (Polish only). We're in the process of moving to a new site and forum so not all information on our old site is up-to-date, but we'll be done soon.
+### IRC channels
+* [#colobot on pirc.pl](irc://pirc.pl#colobot) in Polish;
+* [#colobot on Freenode](irc://freenode.net#colobot) in English;
-PL
+
+# PL
Witamy w repozytorium projektu Colobot
-UWAGA: to jest nowe repozytorium, które zostało przeniesione tu z https://github.com/adiblol/colobot. Nowe repozytorium zostało wyczyszczone z plików binarnych, które zostały w historii, więc wszystkie commity zostały nadpisane. Jeżeli korzystałeś/aś ze starego repozytorium, musisz sklonować od zera te nowe.
+> UWAGA: to jest nowe repozytorium, które zostało przeniesione tu z https://github.com/adiblol/colobot. Nowe repozytorium zostało wyczyszczone z plików binarnych, które zostały w historii, więc wszystkie commity zostały nadpisane. Jeżeli korzystałeś/aś ze starego repozytorium, musisz sklonować od zera te nowe.
To jest oficjalne repozytorium z kodem projektu open-source Colobot rozwijanego przez Polski Portal Colobota (PPC; po angielsku: Polish Portal of Colobot) z oficjalną stroną: http://colobot.info/.
Kod źródłowy zawarty tutaj został wydany przez Epsitec -- oryginalnego twórcę gry -- na otwartej licencji (GPLv3). Kod został wydany i prawa nadane specjalnie dla społeczności PPC w marcu 2012. Od tamtej pory, zajmujemy się modyfikowaniem kodu i pracowaniem nad naszymi celami, które są krótko podsumowane poniżej.
-Więcej informacji dla developerów projektu (po angielsku) można znaleźć na wiki dla developerów: http://colobot.info/wiki/Dev:Main_Page. Jednak źródłem najświeższych informacji jest nasz kanał IRC #colobot na pirc.pl.
+Więcej informacji dla developerów projektu (po angielsku) można znaleźć na [wiki dla developerów](http://colobot.info/wiki/Dev:Main_Page). Jednak źródłem najświeższych informacji jest nasz kanał IRC #colobot na pirc.pl.
To repozytorium zawiera jedynie kod źródłowy projektu. Gra wymaga jeszcze plików danych, które są dostępne w osobnych paczkach, obecnie na stronie http://colobot.info/files. Paczki są nazwane colobot-data-RRRR-MM-DD.zip. Upewnij się, że masz najnowszą wersję paczki zanim skompilujesz i uruchomisz kod z repozytorium.
-Status
+## Status
Nasze główne cele można podsumować w trzech cel, które chcemy osiągnąć:
-Cel 1 - Colobot Classic
+### Cel 1 - Colobot Classic
To jest oryginalna wersja gry, dokładnie taka, jaką otrzymaliśmy od Epsiteca z jedynie niewielkimi zmianami i poprawkami. Jest dostępna jako tag nazwany colobot-original w repozytorium. Ta wersja nie będzie dalej rozwijana. Skompilowaną wersję wraz z potrzebnymi paczkami danych (podzielone wg wersji językowej) można pobrać z http://colobot.info/files.
-Cel 2 - Colobot Gold
+### Cel 2 - Colobot Gold
Jest to wersja gry, którą obecnie rozwijamy w tym repozytorium. Jest oparta na oryginalnym kodzie, ale odświeżonym i przepisanym z wykorzystaniem bibliotek SDL i OpenGL, czyniąc ją wieloplatformową.
-Do września 2012, przepisaliśmy prawie cały oryginalny kod i jesteśmy teraz w trakcie testowania i poprawiania błędów nadal obecnych w grze. Gałąź master zawiera obecny snapshot kodu, który powinien zawsze dać się skompilować i uruchomić z najnowszą paczką danych. Gałęzie dev i podgałęzie dev-* są wykorzystywane do ogólnego rozwoju.
+Do września 2012, przepisaliśmy prawie cały oryginalny kod i jesteśmy teraz w trakcie testowania i poprawiania błędów nadal obecnych w grze. Gałąź master zawiera obecny snapshot kodu, który powinien zawsze dać się skompilować i uruchomić z najnowszą paczką danych. Gałęzie dev i podgałęzie dev-\* są wykorzystywane do ogólnego rozwoju.
-Krok 3 - Colobot 2
+### Krok 3 - Colobot 2
To będzie nowa część z cyklu gier Colobot. Mamy wiele pomysłów na nową grę i nadal dyskutujemy nad nimi. Ogólnie, rozwój tej wersji zacznie się po skończeniu wersji Colobot Gold (prawdopodobnie będzie hostowane w osobnym repozytorium, sforkowanym z kodu Colobot Gold).
-Kompilacja i uruchomienie gry
+## Kompilacja i uruchomienie gry
Instrukcje te znajdują się w pliku HOWTO.txt.
-Kontakt
+## Kontakt
Jeżeli chcesz pomóc w projekcie, prosimy o kontakt na naszym kanale IRC: #colobot na pirc.pl (po polsku i angielsku) albo na forum na naszej stronie: http://colobot.info/forum (jedynie polski). Jesteśmy teraz w trakcie przenoszenia strony i forum w nowe miejsce i nie wszystkie informacje na starej stronie są aktualne, ale już niedługo skończymy przenosiny.
diff --git a/debian/changelog b/debian/changelog
index 75b7e45..0069124 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,4 +1,4 @@
-colobot (0.1.0~pre-alpha-git-dev~re625665-1~OdyX0) UNRELEASED; urgency=low
+colobot (0.1.0~pre-alpha-git-dev~r5a6b3f0-1~OdyX0) UNRELEASED; urgency=low
* Initial release. (Closes: #695829)
diff --git a/debian/control b/debian/control
index 87674f9..d54dc46 100644
--- a/debian/control
+++ b/debian/control
@@ -7,6 +7,7 @@ Build-Depends:
debhelper (>= 9),
cmake,
libgl1-mesa-dev | libgl-dev,
+ libglew-dev,
libsdl1.2-dev (>= 1.2.10),
libsdl-image1.2-dev,
libsdl-ttf2.0-dev,
diff --git a/src/CBot/tests/CBot_console/CMakeLists.txt b/src/CBot/tests/CBot_console/CMakeLists.txt
index 9f0f244..f76dedf 100644
--- a/src/CBot/tests/CBot_console/CMakeLists.txt
+++ b/src/CBot/tests/CBot_console/CMakeLists.txt
@@ -8,7 +8,6 @@ if(NOT CMAKE_BUILD_TYPE)
endif(NOT CMAKE_BUILD_TYPE)
# Global compile flags
-set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wold-style-cast -std=gnu++0x")
set(CMAKE_CXX_FLAGS_RELEASE "-O2")
set(CMAKE_CXX_FLAGS_DEBUG "-g -O0")
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 74de412..c00d347 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -19,32 +19,24 @@ endif()
# Optional libraries
set(OPTIONAL_LIBS "")
-set(OPTIONAL_INCLUDE_DIRS "")
-
-if(${USE_GLEW} AND NOT ${MXE})
- set(OPTIONAL_LIBS ${OPTIONAL_LIBS} ${GLEW_LIBRARY})
- set(OPTIONAL_INCLUDE_DIRS ${OPTIONAL_INCLUDE_DIRS} ${GLEW_INCLUDE_PATH})
-endif()
-
-
-# Additional libraries per platform
-set(PLATFORM_LIBS "")
-set(OPENAL_LIBS "")
if (${OPENAL_SOUND})
if (${MXE})
- set(OPENAL_LIBS
- ${CMAKE_FIND_ROOT_PATH}/lib/libOpenAL32.a
- ${CMAKE_FIND_ROOT_PATH}/lib/libalut.a
- )
+ set(OPTIONAL_LIBS
+ ${CMAKE_FIND_ROOT_PATH}/lib/libOpenAL32.a
+ ${CMAKE_FIND_ROOT_PATH}/lib/libalut.a
+ )
else()
- set(OPENAL_LIBS
- openal
- alut
- )
+ set(OPTIONAL_LIBS
+ openal
+ alut
+ )
endif()
endif()
+# Additional libraries per platform
+set(PLATFORM_LIBS "")
+
if (${MXE}) # MXE requires special treatment
set(PLATFORM_LIBS ${MXE_LIBS})
elseif (${PLATFORM_WINDOWS})
@@ -63,9 +55,9 @@ set(OPENAL_SRC "")
if (${OPENAL_SOUND})
set(OPENAL_SRC
- sound/oalsound/alsound.cpp
- sound/oalsound/buffer.cpp
- sound/oalsound/channel.cpp
+ sound/oalsound/alsound.cpp
+ sound/oalsound/buffer.cpp
+ sound/oalsound/channel.cpp
)
endif()
@@ -89,6 +81,7 @@ graphics/engine/engine.cpp
graphics/engine/lightman.cpp
graphics/engine/lightning.cpp
graphics/engine/modelfile.cpp
+graphics/engine/modelmanager.cpp
graphics/engine/particle.cpp
graphics/engine/planet.cpp
graphics/engine/pyro.cpp
@@ -191,16 +184,16 @@ ${OPENAL_SRC}
set(LIBS
+CBot
${SDL_LIBRARY}
${SDLIMAGE_LIBRARY}
${SDLTTF_LIBRARY}
${OPENGL_LIBRARY}
${PNG_LIBRARIES}
+${GLEW_LIBRARY}
+${Boost_LIBRARIES}
${OPTIONAL_LIBS}
${PLATFORM_LIBS}
-${Boost_LIBRARIES}
-CBot
-${OPENAL_LIBS}
)
include_directories(
@@ -211,8 +204,9 @@ ${SDL_INCLUDE_DIR}
${SDLIMAGE_INCLUDE_DIR}
${SDLTTF_INCLUDE_DIR}
${PNG_INCLUDE_DIRS}
-${OPTIONAL_INCLUDE_DIRS}
+${GLEW_INCLUDE_PATH}
${Boost_INCLUDE_DIRS}
+${OPTIONAL_INCLUDE_DIRS}
)
link_directories(${CMAKE_CURRENT_SOURCE_DIR}/CBot)
diff --git a/src/app/app.cpp b/src/app/app.cpp
index c936ac1..4a69655 100644
--- a/src/app/app.cpp
+++ b/src/app/app.cpp
@@ -26,6 +26,7 @@
#include "common/image.h"
#include "common/key.h"
+#include "graphics/engine/modelmanager.h"
#include "graphics/opengl/gldevice.h"
#include "object/robotmain.h"
@@ -98,6 +99,7 @@ CApplication::CApplication()
m_engine = nullptr;
m_device = nullptr;
+ m_modelManager = nullptr;
m_robotMain = nullptr;
m_sound = nullptr;
@@ -126,6 +128,12 @@ CApplication::CApplication()
m_curTimeStamp = CreateTimeStamp();
m_lastTimeStamp = CreateTimeStamp();
+ for (int i = 0; i < PCNT_MAX; ++i)
+ {
+ m_performanceCounters[i][0] = CreateTimeStamp();
+ m_performanceCounters[i][1] = CreateTimeStamp();
+ }
+
m_joystickEnabled = false;
m_mouseMode = MOUSE_SYSTEM;
@@ -171,6 +179,12 @@ CApplication::~CApplication()
DestroyTimeStamp(m_baseTimeStamp);
DestroyTimeStamp(m_curTimeStamp);
DestroyTimeStamp(m_lastTimeStamp);
+
+ for (int i = 0; i < PCNT_MAX; ++i)
+ {
+ DestroyTimeStamp(m_performanceCounters[i][0]);
+ DestroyTimeStamp(m_performanceCounters[i][1]);
+ }
}
ParseArgsStatus CApplication::ParseArguments(int argc, char *argv[])
@@ -400,6 +414,9 @@ bool CApplication::Create()
return false;
}
+ // Create model manager
+ m_modelManager = new Gfx::CModelManager(m_engine);
+
// Create the robot application.
m_robotMain = new CRobotMain(m_iMan, this);
@@ -427,8 +444,6 @@ bool CApplication::CreateVideoSurface()
// Use hardware surface if available
if (videoInfo->hw_available)
videoFlags |= SDL_HWSURFACE;
- else
- videoFlags |= SDL_SWSURFACE;
// Enable hardware blit if available
if (videoInfo->blit_hw)
@@ -479,6 +494,12 @@ void CApplication::Destroy()
m_sound = nullptr;
}
+ if (m_modelManager != nullptr)
+ {
+ delete m_modelManager;
+ m_modelManager = nullptr;
+ }
+
if (m_engine != nullptr)
{
m_engine->Destroy();
@@ -693,6 +714,14 @@ int CApplication::Run()
while (true)
{
+ ResetPerformanceCounters();
+
+ if (m_active)
+ {
+ StartPerformanceCounter(PCNT_ALL);
+ StartPerformanceCounter(PCNT_EVENT_PROCESSING);
+ }
+
// To be sure no old event remains
m_private->currentEvent.type = SDL_NOEVENT;
@@ -804,15 +833,38 @@ int CApplication::Run()
m_robotMain->EventProcess(event);
}
+ StopPerformanceCounter(PCNT_EVENT_PROCESSING);
+
+ StartPerformanceCounter(PCNT_UPDATE_ALL);
+
+ // Prepare and process step simulation event
+ event = CreateUpdateEvent();
+ if (event.type != EVENT_NULL && m_robotMain != nullptr)
+ {
+ StartPerformanceCounter(PCNT_UPDATE_ENGINE);
+ m_engine->FrameUpdate();
+ StopPerformanceCounter(PCNT_UPDATE_ENGINE);
+
+ m_sound->FrameMove(m_relTime);
+
+ StartPerformanceCounter(PCNT_UPDATE_GAME);
+ m_robotMain->EventProcess(event);
+ StopPerformanceCounter(PCNT_UPDATE_GAME);
+ }
+
+ StopPerformanceCounter(PCNT_UPDATE_ALL);
+
/* Update mouse position explicitly right before rendering
* because mouse events are usually way behind */
UpdateMouse();
- // Update game and render a frame during idle time (no messages are waiting)
+ StartPerformanceCounter(PCNT_RENDER_ALL);
Render();
+ StopPerformanceCounter(PCNT_RENDER_ALL);
+
+ StopPerformanceCounter(PCNT_ALL);
- // Update simulation state
- StepSimulation();
+ UpdatePerformanceCountersData();
if (m_lowCPU)
{
@@ -848,14 +900,14 @@ Event CApplication::ProcessSystemEvent()
{
event.type = EVENT_QUIT;
}
- /*else if (m_private->currentEvent.type == SDL_VIDEORESIZE)
+ else if (m_private->currentEvent.type == SDL_VIDEORESIZE)
{
Gfx::GLDeviceConfig newConfig = m_deviceConfig;
newConfig.size.x = m_private->currentEvent.resize.w;
newConfig.size.y = m_private->currentEvent.resize.h;
if (newConfig.size != m_deviceConfig.size)
ChangeVideoConfig(newConfig);
- }*/
+ }
else if ( (m_private->currentEvent.type == SDL_KEYDOWN) ||
(m_private->currentEvent.type == SDL_KEYUP) )
{
@@ -1142,10 +1194,10 @@ void CApplication::SetSimulationSpeed(float speed)
GetLogger()->Info("Simulation speed = %.2f\n", speed);
}
-void CApplication::StepSimulation()
+Event CApplication::CreateUpdateEvent()
{
if (m_simulationSuspended)
- return;
+ return Event(EVENT_NULL);
CopyTimeStamp(m_lastTimeStamp, m_curTimeStamp);
GetCurrentTimeStamp(m_curTimeStamp);
@@ -1160,11 +1212,6 @@ void CApplication::StepSimulation()
m_exactRelTime = m_simulationSpeed * m_realRelTime;
m_relTime = (m_simulationSpeed * m_realRelTime) / 1e9f;
-
- m_engine->FrameUpdate();
- m_sound->FrameMove(m_relTime);
-
-
Event frameEvent(EVENT_FRAME);
frameEvent.systemEvent = true;
frameEvent.trackedKeysState = m_trackedKeys;
@@ -1172,7 +1219,8 @@ void CApplication::StepSimulation()
frameEvent.mousePos = m_mousePos;
frameEvent.mouseButtonsState = m_mouseButtonsState;
frameEvent.rTime = m_relTime;
- m_eventQueue->AddEvent(frameEvent);
+
+ return frameEvent;
}
float CApplication::GetSimulationSpeed()
@@ -1472,7 +1520,16 @@ void CApplication::SetLanguage(Language language)
if (locale.empty())
{
char *envLang = getenv("LANGUAGE");
- if (strncmp(envLang,"en",2) == 0)
+ if (envLang == NULL)
+ {
+ envLang = getenv("LANG");
+ }
+ if (envLang == NULL)
+ {
+ GetLogger()->Error("Failed to get language from environment, setting default language");
+ m_language = LANGUAGE_ENGLISH;
+ }
+ else if (strncmp(envLang,"en",2) == 0)
{
m_language = LANGUAGE_ENGLISH;
}
@@ -1484,7 +1541,7 @@ void CApplication::SetLanguage(Language language)
{
m_language = LANGUAGE_FRENCH;
}
- else if (strncmp(envLang,"po",2) == 0)
+ else if (strncmp(envLang,"pl",2) == 0)
{
m_language = LANGUAGE_POLISH;
}
@@ -1516,3 +1573,43 @@ bool CApplication::GetLowCPU()
{
return m_lowCPU;
}
+
+void CApplication::StartPerformanceCounter(PerformanceCounter counter)
+{
+ GetCurrentTimeStamp(m_performanceCounters[counter][0]);
+}
+
+void CApplication::StopPerformanceCounter(PerformanceCounter counter)
+{
+ GetCurrentTimeStamp(m_performanceCounters[counter][1]);
+}
+
+float CApplication::GetPerformanceCounterData(PerformanceCounter counter)
+{
+ return m_performanceCountersData[counter];
+}
+
+void CApplication::ResetPerformanceCounters()
+{
+ for (int i = 0; i < PCNT_MAX; ++i)
+ {
+ StartPerformanceCounter(static_cast<PerformanceCounter>(i));
+ StopPerformanceCounter(static_cast<PerformanceCounter>(i));
+ }
+}
+
+void CApplication::UpdatePerformanceCountersData()
+{
+ long long sum = TimeStampExactDiff(m_performanceCounters[PCNT_ALL][0],
+ m_performanceCounters[PCNT_ALL][1]);
+
+ for (int i = 0; i < PCNT_MAX; ++i)
+ {
+ long long diff = TimeStampExactDiff(m_performanceCounters[i][0],
+ m_performanceCounters[i][1]);
+
+ m_performanceCountersData[static_cast<PerformanceCounter>(i)] =
+ static_cast<float>(diff) / static_cast<float>(sum);
+ }
+}
+
diff --git a/src/app/app.h b/src/app/app.h
index 2da20d3..4aa97ce 100644
--- a/src/app/app.h
+++ b/src/app/app.h
@@ -41,6 +41,10 @@ class CEventQueue;
class CRobotMain;
class CSoundInterface;
+namespace Gfx {
+class CModelManager;
+}
+
/**
* \struct JoystickDevice
* \brief Information about a joystick device
@@ -112,6 +116,31 @@ enum MouseMode
MOUSE_NONE, //! < no cursor visible
};
+/**
+ * \enum PerformanceCounter
+ * \brief Type of counter testing performance
+ */
+enum PerformanceCounter
+{
+ PCNT_EVENT_PROCESSING, //! < event processing (except update events)
+
+ PCNT_UPDATE_ALL, //! < the whole frame update process
+ PCNT_UPDATE_ENGINE, //! < frame update in CEngine
+ PCNT_UPDATE_PARTICLE, //! < frame update in CParticle
+ PCNT_UPDATE_GAME, //! < frame update in CRobotMain
+
+ PCNT_RENDER_ALL, //! < the whole rendering process
+ PCNT_RENDER_PARTICLE, //! < rendering the particles in 3D
+ PCNT_RENDER_WATER, //! < rendering the water
+ PCNT_RENDER_TERRAIN, //! < rendering the terrain
+ PCNT_RENDER_OBJECTS, //! < rendering the 3D objects
+ PCNT_RENDER_INTERFACE, //! < rendering 2D interface
+
+ PCNT_ALL, //! < all counters together
+
+ PCNT_MAX
+};
+
struct ApplicationPrivate;
/**
@@ -198,9 +227,6 @@ public:
//! Returns whether simulation is suspended
bool GetSimulationSuspended();
- //! Updates the simulation state
- void StepSimulation();
-
//@{
//! Management of simulation speed
void SetSimulationSpeed(float speed);
@@ -304,6 +330,13 @@ public:
bool GetLowCPU();
//@}
+ //! Management of performance counters
+ //@{
+ void StartPerformanceCounter(PerformanceCounter counter);
+ void StopPerformanceCounter(PerformanceCounter counter);
+ float GetPerformanceCounterData(PerformanceCounter counter);
+ //@}
+
protected:
//! Creates the window's SDL_Surface
bool CreateVideoSurface();
@@ -312,6 +345,8 @@ protected:
Event ProcessSystemEvent();
//! If applicable, creates a virtual event to match the changed state as of new event
Event CreateVirtualEvent(const Event& sourceEvent);
+ //! Prepares a simulation update event
+ Event CreateUpdateEvent();
//! Handles some incoming events
bool ProcessEvent(const Event& event);
//! Renders the image in window
@@ -322,6 +357,11 @@ protected:
//! Closes the joystick device
void CloseJoystick();
+ //! Resets all performance counters to zero
+ void ResetPerformanceCounters();
+ //! Updates performance counters from gathered timer data
+ void UpdatePerformanceCountersData();
+
protected:
//! Instance manager
CInstanceManager* m_iMan;
@@ -333,10 +373,13 @@ protected:
Gfx::CEngine* m_engine;
//! Graphics device
Gfx::CDevice* m_device;
+ //! 3D models manager
+ Gfx::CModelManager* m_modelManager;
//! Sound subsystem
CSoundInterface* m_sound;
//! Main class of the proper game engine
CRobotMain* m_robotMain;
+ //! Profile (INI) reader/writer
CProfile* m_profile;
//! Code to return at exit
@@ -363,6 +406,9 @@ protected:
SystemTimeStamp* m_lastTimeStamp;
SystemTimeStamp* m_curTimeStamp;
+ SystemTimeStamp* m_performanceCounters[PCNT_MAX][2];
+ float m_performanceCountersData[PCNT_MAX];
+
long long m_realAbsTimeBase;
long long m_realAbsTime;
long long m_realRelTime;
diff --git a/src/common/config.h.cmake b/src/common/config.h.cmake
index 022bb69..1595e09 100644
--- a/src/common/config.h.cmake
+++ b/src/common/config.h.cmake
@@ -5,7 +5,6 @@
#cmakedefine PLATFORM_LINUX @PLATFORM_LINUX@
#cmakedefine PLATFORM_OTHER @PLATFORM_OTHER@
-#cmakedefine USE_GLEW @USE_GLEW@
#cmakedefine GLEW_STATIC
#define COLOBOT_VERSION "@COLOBOT_VERSION_FULL@"
diff --git a/src/common/image.cpp b/src/common/image.cpp
index ef8097e..be5711d 100644
--- a/src/common/image.cpp
+++ b/src/common/image.cpp
@@ -190,6 +190,15 @@ Math::IntPoint CImage::GetSize() const
return Math::IntPoint(m_data->surface->w, m_data->surface->h);
}
+/** Image must be valid. */
+void CImage::Fill(Gfx::IntColor color)
+{
+ assert(m_data != nullptr);
+
+ Uint32 c = SDL_MapRGBA(m_data->surface->format, color.r, color.g, color.b, color.a);
+ SDL_FillRect(m_data->surface, nullptr, c);
+}
+
/**
* Image must be valid and pixel coords in valid range.
*
diff --git a/src/common/image.h b/src/common/image.h
index d23a6fa..d9da75b 100644
--- a/src/common/image.h
+++ b/src/common/image.h
@@ -79,6 +79,9 @@ public:
//! Returns the image size
Math::IntPoint GetSize() const;
+ //! Fills the whole image with given color
+ void Fill(Gfx::IntColor color);
+
//! Sets the color at given pixel
void SetPixel(Math::IntPoint pixel, Gfx::Color color);
diff --git a/src/common/test/CMakeLists.txt b/src/common/test/CMakeLists.txt
index 26a31c9..70dac1f 100644
--- a/src/common/test/CMakeLists.txt
+++ b/src/common/test/CMakeLists.txt
@@ -3,7 +3,6 @@ cmake_minimum_required(VERSION 2.8)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE debug)
endif(NOT CMAKE_BUILD_TYPE)
-set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wold-style-cast -std=gnu++0x")
set(CMAKE_CXX_FLAGS_DEBUG "-g -O0")
include_directories(
diff --git a/src/desktop/colobot.desktop.in b/src/desktop/colobot.desktop.in
index 74378fd..9b09803 100644
--- a/src/desktop/colobot.desktop.in
+++ b/src/desktop/colobot.desktop.in
@@ -3,3 +3,4 @@ Version=1.0
Type=Application
Exec=colobot
Icon=colobot
+Categories=Education;Robotics;Game;AdventureGame;StrategyGame;
diff --git a/src/graphics/core/device.h b/src/graphics/core/device.h
index b6dd138..41d7796 100644
--- a/src/graphics/core/device.h
+++ b/src/graphics/core/device.h
@@ -104,8 +104,7 @@ enum RenderState
RENDER_STATE_DEPTH_TEST,
RENDER_STATE_DEPTH_WRITE,
RENDER_STATE_ALPHA_TEST,
- RENDER_STATE_CULLING,
- RENDER_STATE_DITHERING
+ RENDER_STATE_CULLING
};
/**
@@ -204,22 +203,22 @@ enum PrimitiveType
};
/**
- * \enum IntersectPlane
- * \brief Intersection plane of projection volume
+ * \enum FrustumPlane
+ * \brief Planes of frustum space
*
- * These flags can be OR'd together.
+ * Bitset of flags - can be OR'd together.
*/
-enum IntersectPlane
+enum FrustumPlane
{
- INTERSECT_PLANE_LEFT = 0x01,
- INTERSECT_PLANE_RIGHT = 0x02,
- INTERSECT_PLANE_TOP = 0x04,
- INTERSECT_PLANE_BOTTOM = 0x08,
- INTERSECT_PLANE_FRONT = 0x10,
- INTERSECT_PLANE_BACK = 0x20,
- INTERSECT_PLANE_ALL = INTERSECT_PLANE_LEFT | INTERSECT_PLANE_RIGHT |
- INTERSECT_PLANE_TOP | INTERSECT_PLANE_BOTTOM |
- INTERSECT_PLANE_FRONT | INTERSECT_PLANE_BACK
+ FRUSTUM_PLANE_LEFT = 0x01,
+ FRUSTUM_PLANE_RIGHT = 0x02,
+ FRUSTUM_PLANE_TOP = 0x04,
+ FRUSTUM_PLANE_BOTTOM = 0x08,
+ FRUSTUM_PLANE_FRONT = 0x10,
+ FRUSTUM_PLANE_BACK = 0x20,
+ FRUSTUM_PLANE_ALL = FRUSTUM_PLANE_LEFT | FRUSTUM_PLANE_RIGHT |
+ FRUSTUM_PLANE_TOP | FRUSTUM_PLANE_BOTTOM |
+ FRUSTUM_PLANE_FRONT | FRUSTUM_PLANE_BACK
};
/**
@@ -287,7 +286,7 @@ public:
virtual void DestroyAllTextures() = 0;
//! Returns the maximum number of multitexture stages
- virtual int GetMaxTextureCount() = 0;
+ virtual int GetMaxTextureStageCount() = 0;
//! Sets the texture at given texture stage
virtual void SetTexture(int index, const Texture &texture) = 0;
//! Sets the texture image by ID at given texture stage
@@ -313,10 +312,35 @@ public:
//! Renders primitive composed of vertices with multitexturing (2 textures)
virtual void DrawPrimitive(PrimitiveType type, const VertexTex2 *vertices, int vertexCount,
Color color = Color(1.0f, 1.0f, 1.0f, 1.0f)) = 0;
- //! Renders primitive composed of vertices with color information
+ //! Renders primitive composed of vertices with solid color
virtual void DrawPrimitive(PrimitiveType type, const VertexCol *vertices , int vertexCount) = 0;
- //! Tests whether a sphere intersects the 6 clipping planes of projection volume
+ //! Creates a static buffer composed of given primitives with single texture vertices
+ virtual unsigned int CreateStaticBuffer(PrimitiveType primitiveType, const Vertex* vertices, int vertexCount) = 0;
+
+ //! Creates a static buffer composed of given primitives with multitexturing
+ virtual unsigned int CreateStaticBuffer(PrimitiveType primitiveType, const VertexTex2* vertices, int vertexCount) = 0;
+
+ //! Creates a static buffer composed of given primitives with solid color
+ virtual unsigned int CreateStaticBuffer(PrimitiveType primitiveType, const VertexCol* vertices, int vertexCount) = 0;
+
+ //! Updates the static buffer composed of given primitives with single texture vertices
+ virtual void UpdateStaticBuffer(unsigned int bufferId, PrimitiveType primitiveType, const Vertex* vertices, int vertexCount) = 0;
+
+ //! Updates the static buffer composed of given primitives with multitexturing
+ virtual void UpdateStaticBuffer(unsigned int bufferId, PrimitiveType primitiveType, const VertexTex2* vertices, int vertexCount) = 0;
+
+ //! Updates the static buffer composed of given primitives with solid color
+ virtual void UpdateStaticBuffer(unsigned int bufferId, PrimitiveType primitiveType, const VertexCol* vertices, int vertexCount) = 0;
+
+ //! Draws a static buffer
+ virtual void DrawStaticBuffer(unsigned int bufferId) = 0;
+
+ //! Deletes a static buffer
+ virtual void DestroyStaticBuffer(unsigned int bufferId) = 0;
+
+ //! Tests whether a sphere is (partially) within the frustum volume
+ //! Returns a mask of frustum planes for which the test is positive
virtual int ComputeSphereVisibility(const Math::Vector &center, float radius) = 0;
//! Enables/disables the given render state
diff --git a/src/graphics/core/vertex.h b/src/graphics/core/vertex.h
index 2ee6be4..66e1503 100644
--- a/src/graphics/core/vertex.h
+++ b/src/graphics/core/vertex.h
@@ -44,23 +44,18 @@ namespace Gfx {
* - vertex coordinates (x,y,z) as Math::Vector,
* - normal coordinates (nx,ny,nz) as Math::Vector
* - texture coordinates (u,v) as Math::Point.
- *
- * Additional padding is provided to align to even multiplies of 4 floats for faster access.
*/
struct Vertex
{
Math::Vector coord;
- float pad1;
Math::Vector normal;
- float pad2;
Math::Point texCoord;
- float pad3, pad4;
explicit Vertex(Math::Vector aCoord = Math::Vector(),
Math::Vector aNormal = Math::Vector(),
Math::Point aTexCoord = Math::Point())
- : coord(aCoord), pad1(0.0f), normal(aNormal),
- pad2(0.0f),texCoord(aTexCoord), pad3(0.0f), pad4(0.0f) {}
+ : coord(aCoord), normal(aNormal),
+ texCoord(aTexCoord) {}
//! Returns a string "(c: [...], n: [...], tc: [...])"
@@ -81,18 +76,15 @@ struct Vertex
* It contains:
* - vertex coordinates (x,y,z) as Math::Vector,
* - RGBA color as Color
- *
- * Additional padding is provided to align to even multiplies of 4 floats for faster access.
*/
struct VertexCol
{
Math::Vector coord;
- float pad;
Color color;
explicit VertexCol(Math::Vector aCoord = Math::Vector(),
Color aColor = Color())
- : coord(aCoord), pad(0.0f), color(aColor) {}
+ : coord(aCoord), color(aColor) {}
//! Returns a string "(c: [...], col: [...])"
inline std::string ToString() const
@@ -111,15 +103,11 @@ struct VertexCol
*
* In addition to fields from Vector, it contains
* secondary texture coordinates (u2, v2) as Math::Point
- *
- * Additional padding is provided to align to even multiplies of 4 floats for faster access.
*/
struct VertexTex2
{
Math::Vector coord;
- float pad1;
Math::Vector normal;
- float pad2;
Math::Point texCoord;
Math::Point texCoord2;
@@ -127,7 +115,7 @@ struct VertexTex2
Math::Vector aNormal = Math::Vector(),
Math::Point aTexCoord = Math::Point(),
Math::Point aTexCoord2 = Math::Point())
- : coord(aCoord), pad1(0.0f), normal(aNormal), pad2(0.0f),
+ : coord(aCoord), normal(aNormal),
texCoord(aTexCoord), texCoord2(aTexCoord2) {}
//! Sets the fields from Vertex with texCoord2 = (0,0)
diff --git a/src/graphics/engine/engine.cpp b/src/graphics/engine/engine.cpp
index 3365b24..7c90a8d 100644
--- a/src/graphics/engine/engine.cpp
+++ b/src/graphics/engine/engine.cpp
@@ -47,55 +47,6 @@
// Graphics module namespace
namespace Gfx {
-
-// Initial size of various vectors
-const int OBJECT_PREALLOCATE_COUNT = 1200;
-const int SHADOW_PREALLOCATE_COUNT = 500;
-const int GROUNDSPOT_PREALLOCATE_COUNT = 100;
-
-const int LEVEL1_PREALLOCATE_COUNT = 50;
-const int LEVEL2_PREALLOCATE_COUNT = 100;
-const int LEVEL3_PREALLOCATE_COUNT = 5;
-const int LEVEL4_PREALLOCATE_COUNT = 100;
-const int LEVEL4_VERTEX_PREALLOCATE_COUNT = 200;
-
-
-EngineObjLevel1::EngineObjLevel1(bool used, const std::string& tex1Name, const std::string& tex2Name)
-{
- this->used = used;
- this->tex1Name = tex1Name;
- this->tex2Name = tex2Name;
-
- next.reserve(LEVEL2_PREALLOCATE_COUNT);
-}
-
-EngineObjLevel2::EngineObjLevel2(bool used, int objRank)
-{
- this->used = used;
- this->objRank = objRank;
-
- next.reserve(LEVEL3_PREALLOCATE_COUNT);
-}
-
-EngineObjLevel3::EngineObjLevel3(bool used, float min, float max)
-{
- this->used = used;
- this->min = min;
- this->max = max;
-
- next.reserve(LEVEL4_PREALLOCATE_COUNT);
-}
-
-EngineObjLevel4::EngineObjLevel4(bool used, EngineTriangleType type, const Material& material, int state)
-{
- this->used = used;
- this->type = type;
- this->material = material;
- this->state = state;
-
- vertices.reserve(LEVEL4_VERTEX_PREALLOCATE_COUNT);
-}
-
CEngine::CEngine(CInstanceManager *iMan, CApplication *app)
{
m_iMan = iMan;
@@ -182,6 +133,7 @@ CEngine::CEngine(CInstanceManager *iMan, CApplication *app)
m_alphaMode = 1;
m_updateGeometry = false;
+ m_updateStaticBuffers = false;
m_interfaceMode = false;
@@ -218,11 +170,6 @@ CEngine::CEngine(CInstanceManager *iMan, CApplication *app)
m_terrainTexParams.mipmap = false;
m_terrainTexParams.minFilter = TEX_MIN_FILTER_LINEAR;
m_terrainTexParams.magFilter = TEX_MAG_FILTER_LINEAR;
-
- m_objectTree.reserve(LEVEL1_PREALLOCATE_COUNT);
- m_objects.reserve(OBJECT_PREALLOCATE_COUNT);
- m_shadows.reserve(SHADOW_PREALLOCATE_COUNT);
- m_groundSpots.reserve(GROUNDSPOT_PREALLOCATE_COUNT);
}
CEngine::~CEngine()
@@ -334,6 +281,8 @@ void CEngine::Destroy()
void CEngine::ResetAfterDeviceChanged()
{
+ m_size = m_app->GetVideoConfig().size;;
+
m_text->FlushCache();
// TODO reload textures, reset device state, etc.
@@ -378,9 +327,14 @@ void CEngine::FrameUpdate()
float rTime = m_app->GetRelTime();
m_lightMan->UpdateProgression(rTime);
+
+ m_app->StartPerformanceCounter(PCNT_UPDATE_PARTICLE);
m_particle->FrameParticle(rTime);
+ m_app->StopPerformanceCounter(PCNT_UPDATE_PARTICLE);
+
ComputeDistance();
UpdateGeometry();
+ UpdateStaticBuffers();
m_highlightTime = m_app->GetAbsTime();
@@ -409,7 +363,7 @@ void CEngine::FrameUpdate()
{
m_groundMark.intensity = 0.0f;
m_groundMark.phase = ENG_GR_MARK_PHASE_NULL;
- m_groundMark.draw = false;
+ m_groundMark.draw = false;
}
}
}
@@ -422,18 +376,6 @@ bool CEngine::WriteScreenShot(const std::string& fileName, int width, int height
return true;
}
-bool CEngine::ReadSettings()
-{
- // TODO: when INI reading is completed
- return true;
-}
-
-bool CEngine::WriteSettings()
-{
- // TODO: when INI writing is completed
- return true;
-}
-
void CEngine::SetPause(bool pause)
{
m_pause = pause;
@@ -500,7 +442,7 @@ Math::Point CEngine::WindowToInterfaceSize(Math::IntPoint size)
Math::IntPoint CEngine::InterfaceToWindowSize(Math::Point size)
{
return Math::IntPoint(static_cast<int>(size.x * m_size.x),
- static_cast<int>(size.y * m_size.y));
+ static_cast<int>(size.y * m_size.y));
}
void CEngine::AddStatisticTriangle(int count)
@@ -519,480 +461,377 @@ int CEngine::GetStatisticTriangle()
Object management
*******************************************************/
+EngineBaseObjTexTier& CEngine::AddLevel2(EngineBaseObject& p1, const std::string& tex1Name, const std::string& tex2Name)
+{
+ for (int i = 0; i < static_cast<int>( p1.next.size() ); i++)
+ {
+ if (p1.next[i].tex1Name == tex1Name && p1.next[i].tex2Name == tex2Name)
+ return p1.next[i];
+ }
+ p1.next.push_back(EngineBaseObjTexTier(tex1Name, tex2Name));
+ return p1.next.back();
+}
-int CEngine::CreateObject()
+EngineBaseObjLODTier& CEngine::AddLevel3(EngineBaseObjTexTier& p2, float min, float max)
{
- int i = 0;
- for ( ; i < static_cast<int>( m_objects.size() ); i++)
+ for (int i = 0; i < static_cast<int>( p2.next.size() ); i++)
{
- if (! m_objects[i].used)
+ if ( (p2.next[i].min == min) && (p2.next[i].max == max) )
+ return p2.next[i];
+ }
+
+ p2.next.push_back(EngineBaseObjLODTier(min, max));
+ return p2.next.back();
+}
+
+EngineBaseObjDataTier& CEngine::AddLevel4(EngineBaseObjLODTier& p3, EngineTriangleType type,
+ const Material& material, int state)
+{
+ for (int i = 0; i < static_cast<int>( p3.next.size() ); i++)
+ {
+ if ( (p3.next[i].type == type) && (p3.next[i].material == material) && (p3.next[i].state == state) )
+ return p3.next[i];
+ }
+
+ p3.next.push_back(EngineBaseObjDataTier(type, material, state));
+ return p3.next.back();
+}
+
+int CEngine::CreateBaseObject()
+{
+ int baseObjRank = 0;
+ for ( ; baseObjRank < static_cast<int>( m_baseObjects.size() ); baseObjRank++)
+ {
+ if (! m_baseObjects[baseObjRank].used)
{
- m_objects[i].LoadDefault();
+ m_baseObjects[baseObjRank].LoadDefault();
break;
}
}
- if (i == static_cast<int>( m_objects.size() ))
- m_objects.push_back(EngineObject());
-
+ if (baseObjRank == static_cast<int>( m_baseObjects.size() ))
+ m_baseObjects.push_back(EngineBaseObject());
+ else
+ m_baseObjects[baseObjRank].LoadDefault();
- m_objects[i].used = true;
- Math::Matrix mat;
- mat.LoadIdentity();
- SetObjectTransform(i, mat);
+ m_baseObjects[baseObjRank].used = true;
- m_objects[i].drawWorld = true;
- m_objects[i].distance = 0.0f;
- m_objects[i].bboxMin = Math::Vector(0.0f, 0.0f, 0.0f);
- m_objects[i].bboxMax = Math::Vector(0.0f, 0.0f, 0.0f);
- m_objects[i].shadowRank = -1;
-
- return i;
+ return baseObjRank;
}
-void CEngine::FlushObject()
+void CEngine::DeleteBaseObject(int baseObjRank)
{
- m_objectTree.clear();
- m_objects.clear();
+ assert(baseObjRank >= 0 && baseObjRank < static_cast<int>( m_baseObjects.size() ));
- m_shadows.clear();
+ EngineBaseObject& p1 = m_baseObjects[baseObjRank];
- FlushGroundSpot();
-}
-
-bool CEngine::DeleteObject(int objRank)
-{
- if ( objRank < 0 || objRank >= static_cast<int>( m_objects.size() ) )
- return false;
+ if (! p1.used)
+ return;
- // Delete object's triangles
- for (int l1 = 0; l1 < static_cast<int>( m_objectTree.size() ); l1++)
+ for (int l2 = 0; l2 < static_cast<int>( p1.next.size() ); l2++)
{
- EngineObjLevel1& p1 = m_objectTree[l1];
- if (! p1.used) continue;
+ EngineBaseObjTexTier& p2 = p1.next[l2];
- for (int l2 = 0; l2 < static_cast<int>( p1.next.size() ); l2++)
+ for (int l3 = 0; l3 < static_cast<int>( p2.next.size() ); l3++)
{
- EngineObjLevel2& p2 = p1.next[l2];
- if (! p2.used) continue;
+ EngineBaseObjLODTier& p3 = p2.next[l3];
- if (p2.objRank == objRank)
+ for (int l4 = 0; l4 < static_cast<int>( p3.next.size() ); l4++)
{
- p2.used = false;
- p2.next.clear();
+ EngineBaseObjDataTier& p4 = p3.next[l4];
+
+ m_device->DestroyStaticBuffer(p4.staticBufferId);
+ p4.staticBufferId = 0;
}
}
}
- // Mark object as deleted
- m_objects[objRank].used = false;
+ p1.next.clear();
- // Delete associated shadows
- DeleteShadow(objRank);
-
- return true;
+ p1.used = false;
}
-bool CEngine::SetObjectType(int objRank, EngineObjectType type)
+void CEngine::DeleteAllBaseObjects()
{
- if ( objRank < 0 || objRank >= static_cast<int>( m_objects.size() ) )
- return false;
-
- m_objects[objRank].type = type;
- return true;
-}
-
-EngineObjectType CEngine::GetObjectType(int objRank)
-{
- if ( objRank < 0 || objRank >= static_cast<int>( m_objects.size() ) )
- return ENG_OBJTYPE_NULL;
-
- return m_objects[objRank].type;
+ m_baseObjects.clear();
}
-
-bool CEngine::SetObjectTransform(int objRank, const Math::Matrix& transform)
+void CEngine::CopyBaseObject(int sourceBaseObjRank, int destBaseObjRank)
{
- if ( objRank < 0 || objRank >= static_cast<int>( m_objects.size() ) )
- return false;
+ assert(sourceBaseObjRank >= 0 && sourceBaseObjRank < static_cast<int>( m_baseObjects.size() ));
+ assert(destBaseObjRank >= 0 && destBaseObjRank < static_cast<int>( m_baseObjects.size() ));
- m_objects[objRank].transform = transform;
- return true;
+ m_baseObjects[destBaseObjRank] = m_baseObjects[sourceBaseObjRank];
}
-bool CEngine::GetObjectTransform(int objRank, Math::Matrix& transform)
+void CEngine::AddBaseObjTriangles(int baseObjRank, const std::vector<VertexTex2>& vertices,
+ EngineTriangleType triangleType,
+ const Material& material, int state,
+ std::string tex1Name, std::string tex2Name,
+ float min, float max, bool globalUpdate)
{
- if ( objRank < 0 || objRank >= static_cast<int>( m_objects.size() ) )
- return false;
+ assert(baseObjRank >= 0 && baseObjRank < static_cast<int>( m_baseObjects.size() ));
- transform = m_objects[objRank].transform;
- return true;
-}
+ m_lastSize = m_size;
+ m_lastObjectDetail = m_objectDetail;
+ m_lastClippingDistance = m_clippingDistance;
-bool CEngine::SetObjectDrawWorld(int objRank, bool draw)
-{
- if ( objRank < 0 || objRank >= static_cast<int>( m_objects.size() ) )
- return false;
+ EngineBaseObject& p1 = m_baseObjects[baseObjRank];
+ EngineBaseObjTexTier& p2 = AddLevel2(p1, tex1Name, tex2Name);
+ EngineBaseObjLODTier& p3 = AddLevel3(p2, min, max);
+ EngineBaseObjDataTier& p4 = AddLevel4(p3, triangleType, material, state);
- m_objects[objRank].drawWorld = draw;
- return true;
-}
+ p4.vertices.insert(p4.vertices.end(), vertices.begin(), vertices.end());
-bool CEngine::SetObjectDrawFront(int objRank, bool draw)
-{
- if ( objRank < 0 || objRank >= static_cast<int>( m_objects.size() ) )
- return false;
+ p4.updateStaticBuffer = true;
+ m_updateStaticBuffers = true;
- m_objects[objRank].drawFront = draw;
- return true;
-}
+ if (globalUpdate)
+ {
+ m_updateGeometry = true;
+ }
+ else
+ {
+ for (int i = 0; i < static_cast<int>( vertices.size() ); i++)
+ {
+ p1.bboxMin.x = Math::Min(vertices[i].coord.x, p1.bboxMin.x);
+ p1.bboxMin.y = Math::Min(vertices[i].coord.y, p1.bboxMin.y);
+ p1.bboxMin.z = Math::Min(vertices[i].coord.z, p1.bboxMin.z);
+ p1.bboxMax.x = Math::Max(vertices[i].coord.x, p1.bboxMax.x);
+ p1.bboxMax.y = Math::Max(vertices[i].coord.y, p1.bboxMax.y);
+ p1.bboxMax.z = Math::Max(vertices[i].coord.z, p1.bboxMax.z);
+ }
-bool CEngine::SetObjectTransparency(int objRank, float value)
-{
- if ( objRank < 0 || objRank >= static_cast<int>( m_objects.size() ) )
- return false;
+ p1.radius = Math::Max(p1.bboxMin.Length(), p1.bboxMax.Length());
+ }
- m_objects[objRank].transparency = value;
- return true;
+ if (triangleType == ENG_TRIANGLE_TYPE_TRIANGLES)
+ p1.totalTriangles += vertices.size() / 3;
+ else
+ p1.totalTriangles += vertices.size() - 2;
}
-bool CEngine::GetObjectBBox(int objRank, Math::Vector& min, Math::Vector& max)
+void CEngine::AddBaseObjQuick(int baseObjRank, const EngineBaseObjDataTier& buffer,
+ std::string tex1Name, std::string tex2Name,
+ float min, float max, bool globalUpdate)
{
- if ( objRank < 0 || objRank >= static_cast<int>( m_objects.size() ) )
- return 0;
+ assert(baseObjRank >= 0 && baseObjRank < static_cast<int>( m_baseObjects.size() ));
- min = m_objects[objRank].bboxMin;
- max = m_objects[objRank].bboxMax;
- return true;
-}
+ EngineBaseObject& p1 = m_baseObjects[baseObjRank];
+ EngineBaseObjTexTier& p2 = AddLevel2(p1, tex1Name, tex2Name);
+ EngineBaseObjLODTier& p3 = AddLevel3(p2, min, max);
+ p3.next.push_back(buffer);
-int CEngine::GetObjectTotalTriangles(int objRank)
-{
- if ( objRank < 0 || objRank >= static_cast<int>( m_objects.size() ) )
- return 0;
+ EngineBaseObjDataTier& p4 = p3.next.back();
- return m_objects[objRank].totalTriangles;
-}
+ UpdateStaticBuffer(p4);
-
-EngineObjLevel1& CEngine::AddLevel1(const std::string& tex1Name, const std::string& tex2Name)
-{
- bool unusedPresent = false;
- for (int i = 0; i < static_cast<int>( m_objectTree.size() ); i++)
+ if (globalUpdate)
{
- if (! m_objectTree[i].used)
- {
- unusedPresent = true;
- continue;
- }
-
- if (m_objectTree[i].tex1Name == tex1Name && m_objectTree[i].tex2Name == tex2Name)
- return m_objectTree[i];
+ m_updateGeometry = true;
}
-
- if (unusedPresent)
+ else
{
- for (int i = 0; i < static_cast<int>( m_objectTree.size() ); i++)
+ for (int i = 0; i < static_cast<int>( p4.vertices.size() ); i++)
{
- if (! m_objectTree[i].used)
- {
- m_objectTree[i].used = true;
- m_objectTree[i].tex1Name = tex1Name;
- m_objectTree[i].tex2Name = tex2Name;
- return m_objectTree[i];
- }
+ p1.bboxMin.x = Math::Min(p4.vertices[i].coord.x, p1.bboxMin.x);
+ p1.bboxMin.y = Math::Min(p4.vertices[i].coord.y, p1.bboxMin.y);
+ p1.bboxMin.z = Math::Min(p4.vertices[i].coord.z, p1.bboxMin.z);
+ p1.bboxMax.x = Math::Max(p4.vertices[i].coord.x, p1.bboxMax.x);
+ p1.bboxMax.y = Math::Max(p4.vertices[i].coord.y, p1.bboxMax.y);
+ p1.bboxMax.z = Math::Max(p4.vertices[i].coord.z, p1.bboxMax.z);
}
+
+ p1.radius = Math::Max(p1.bboxMin.Length(), p1.bboxMax.Length());
}
- m_objectTree.push_back(EngineObjLevel1(true, tex1Name, tex2Name));
- return m_objectTree.back();
+ if (p4.type == ENG_TRIANGLE_TYPE_TRIANGLES)
+ p1.totalTriangles += p4.vertices.size() / 3;
+ else if (p4.type == ENG_TRIANGLE_TYPE_SURFACE)
+ p1.totalTriangles += p4.vertices.size() - 2;
}
-EngineObjLevel2& CEngine::AddLevel2(EngineObjLevel1& p1, int objRank)
+
+int CEngine::CreateObject()
{
- bool unusedPresent = false;
- for (int i = 0; i < static_cast<int>( p1.next.size() ); i++)
+ int objRank = 0;
+ for ( ; objRank < static_cast<int>( m_objects.size() ); objRank++)
{
- if (! p1.next[i].used)
+ if (! m_objects[objRank].used)
{
- unusedPresent = true;
- continue;
+ m_objects[objRank].LoadDefault();
+ break;
}
-
- if (p1.next[i].objRank == objRank)
- return p1.next[i];
}
- if (unusedPresent)
- {
- for (int i = 0; i < static_cast<int>( p1.next.size() ); i++)
- {
- if (! p1.next[i].used)
- {
- p1.next[i].used = true;
- p1.next[i].objRank = objRank;
- return p1.next[i];
- }
- }
- }
+ if (objRank == static_cast<int>( m_objects.size() ))
+ m_objects.push_back(EngineObject());
- p1.next.push_back(EngineObjLevel2(true, objRank));
- return p1.next.back();
+
+ m_objects[objRank].used = true;
+
+ Math::Matrix mat;
+ mat.LoadIdentity();
+ SetObjectTransform(objRank, mat);
+
+ m_objects[objRank].drawWorld = true;
+ m_objects[objRank].distance = 0.0f;
+ m_objects[objRank].shadowRank = -1;
+
+ return objRank;
}
-EngineObjLevel3& CEngine::AddLevel3(EngineObjLevel2& p2, float min, float max)
+void CEngine::DeleteAllObjects()
{
- bool unusedPresent = false;
- for (int i = 0; i < static_cast<int>( p2.next.size() ); i++)
- {
- if (! p2.next[i].used)
- {
- unusedPresent = true;
- continue;
- }
+ m_objects.clear();
+ m_shadows.clear();
- if ( (p2.next[i].min == min) && (p2.next[i].max == max) )
- return p2.next[i];
- }
+ DeleteAllGroundSpots();
+}
- if (unusedPresent)
- {
- for (int i = 0; i < static_cast<int>( p2.next.size() ); i++)
- {
- if (! p2.next[i].used)
- {
- p2.next[i].used = true;
- p2.next[i].min = min;
- p2.next[i].max = max;
- return p2.next[i];
- }
- }
- }
+void CEngine::DeleteObject(int objRank)
+{
+ assert(objRank >= 0 && objRank < static_cast<int>( m_objects.size() ));
- p2.next.push_back(EngineObjLevel3(true, min, max));
- return p2.next.back();
+ // Mark object as deleted
+ m_objects[objRank].used = false;
+
+ // Delete associated shadows
+ DeleteShadow(objRank);
}
-EngineObjLevel4& CEngine::AddLevel4(EngineObjLevel3& p3, EngineTriangleType type,
- const Material& material, int state)
+void CEngine::SetObjectBaseRank(int objRank, int baseObjRank)
{
- bool unusedPresent = false;
- for (int i = 0; i < static_cast<int>( p3.next.size() ); i++)
- {
- if (! p3.next[i].used)
- {
- unusedPresent = true;
- continue;
- }
+ assert(objRank == -1 || (objRank >= 0 && objRank < static_cast<int>( m_objects.size() )));
- if ( (p3.next[i].type == type) && (p3.next[i].material == material) && (p3.next[i].state == state) )
- return p3.next[i];
- }
+ m_objects[objRank].baseObjRank = baseObjRank;
+}
- if (unusedPresent)
- {
- for (int i = 0; i < static_cast<int>( p3.next.size() ); i++)
- {
- if (! p3.next[i].used)
- {
- p3.next[i].used = true;
- p3.next[i].type = type;
- p3.next[i].material = material;
- p3.next[i].state = state;
- return p3.next[i];
- }
- }
- }
+int CEngine::GetObjectBaseRank(int objRank)
+{
+ assert(objRank >= 0 && objRank < static_cast<int>( m_objects.size() ));
- p3.next.push_back(EngineObjLevel4(true, type, material, state));
- return p3.next.back();
+ return m_objects[objRank].baseObjRank;
}
-bool CEngine::AddTriangles(int objRank, const std::vector<VertexTex2>& vertices,
- const Material& material, int state,
- std::string tex1Name, std::string tex2Name,
- float min, float max, bool globalUpdate)
+void CEngine::SetObjectType(int objRank, EngineObjectType type)
{
- if ( objRank < 0 || objRank >= static_cast<int>( m_objects.size() ) )
- {
- GetLogger()->Error("AddTriangle(): invalid object rank %d\n", objRank);
- return false;
- }
+ assert(objRank >= 0 && objRank < static_cast<int>( m_objects.size() ));
- m_lastSize = m_size;
- m_lastObjectDetail = m_objectDetail;
- m_lastClippingDistance = m_clippingDistance;
+ m_objects[objRank].type = type;
+}
- EngineObjLevel1& p1 = AddLevel1(tex1Name, tex2Name);
- EngineObjLevel2& p2 = AddLevel2(p1, objRank);
- EngineObjLevel3& p3 = AddLevel3(p2, min, max);
- EngineObjLevel4& p4 = AddLevel4(p3, ENG_TRIANGLE_TYPE_TRIANGLES, material, state);
+EngineObjectType CEngine::GetObjectType(int objRank)
+{
+ assert(objRank >= 0 && objRank < static_cast<int>( m_objects.size() ));
- p4.vertices.insert(p4.vertices.end(), vertices.begin(), vertices.end());
+ return m_objects[objRank].type;
+}
- if (globalUpdate)
- {
- m_updateGeometry = true;
- }
- else
- {
- for (int i = 0; i < static_cast<int>( vertices.size() ); i++)
- {
- m_objects[objRank].bboxMin.x = Math::Min(vertices[i].coord.x, m_objects[objRank].bboxMin.x);
- m_objects[objRank].bboxMin.y = Math::Min(vertices[i].coord.y, m_objects[objRank].bboxMin.y);
- m_objects[objRank].bboxMin.z = Math::Min(vertices[i].coord.z, m_objects[objRank].bboxMin.z);
- m_objects[objRank].bboxMax.x = Math::Max(vertices[i].coord.x, m_objects[objRank].bboxMax.x);
- m_objects[objRank].bboxMax.y = Math::Max(vertices[i].coord.y, m_objects[objRank].bboxMax.y);
- m_objects[objRank].bboxMax.z = Math::Max(vertices[i].coord.z, m_objects[objRank].bboxMax.z);
- }
- m_objects[objRank].radius = Math::Max(m_objects[objRank].bboxMin.Length(),
- m_objects[objRank].bboxMax.Length());
- }
-
- m_objects[objRank].totalTriangles += vertices.size() / 3;
+void CEngine::SetObjectTransform(int objRank, const Math::Matrix& transform)
+{
+ assert(objRank >= 0 && objRank < static_cast<int>( m_objects.size() ));
- return true;
+ m_objects[objRank].transform = transform;
}
-bool CEngine::AddSurface(int objRank, const std::vector<VertexTex2>& vertices,
- const Material& material, int state,
- std::string tex1Name, std::string tex2Name,
- float min, float max, bool globalUpdate)
+void CEngine::GetObjectTransform(int objRank, Math::Matrix& transform)
{
- if ( objRank < 0 || objRank >= static_cast<int>( m_objects.size() ) )
- {
- GetLogger()->Error("AddSurface(): invalid object rank %d\n", objRank);
- return false;
- }
+ assert(objRank >= 0 && objRank < static_cast<int>( m_objects.size() ));
- m_lastSize = m_size;
- m_lastObjectDetail = m_objectDetail;
- m_lastClippingDistance = m_clippingDistance;
+ transform = m_objects[objRank].transform;
+}
- EngineObjLevel1& p1 = AddLevel1(tex1Name, tex2Name);
- EngineObjLevel2& p2 = AddLevel2(p1, objRank);
- EngineObjLevel3& p3 = AddLevel3(p2, min, max);
- EngineObjLevel4& p4 = AddLevel4(p3, ENG_TRIANGLE_TYPE_SURFACE, material, state);
+void CEngine::SetObjectDrawWorld(int objRank, bool draw)
+{
+ assert(objRank >= 0 && objRank < static_cast<int>( m_objects.size() ));
- p4.vertices.insert(p4.vertices.end(), vertices.begin(), vertices.end());
+ m_objects[objRank].drawWorld = draw;
+}
- if (globalUpdate)
- {
- m_updateGeometry = true;
- }
- else
- {
- for (int i = 0; i < static_cast<int>( vertices.size() ); i++)
- {
- m_objects[objRank].bboxMin.x = Math::Min(vertices[i].coord.x, m_objects[objRank].bboxMin.x);
- m_objects[objRank].bboxMin.y = Math::Min(vertices[i].coord.y, m_objects[objRank].bboxMin.y);
- m_objects[objRank].bboxMin.z = Math::Min(vertices[i].coord.z, m_objects[objRank].bboxMin.z);
- m_objects[objRank].bboxMax.x = Math::Max(vertices[i].coord.x, m_objects[objRank].bboxMax.x);
- m_objects[objRank].bboxMax.y = Math::Max(vertices[i].coord.y, m_objects[objRank].bboxMax.y);
- m_objects[objRank].bboxMax.z = Math::Max(vertices[i].coord.z, m_objects[objRank].bboxMax.z);
- }
+void CEngine::SetObjectDrawFront(int objRank, bool draw)
+{
+ assert(objRank >= 0 && objRank < static_cast<int>( m_objects.size() ));
- m_objects[objRank].radius = Math::Max(m_objects[objRank].bboxMin.Length(),
- m_objects[objRank].bboxMax.Length());
- }
+ m_objects[objRank].drawFront = draw;
+}
- m_objects[objRank].totalTriangles += vertices.size() - 2;
+void CEngine::SetObjectTransparency(int objRank, float value)
+{
+ assert(objRank >= 0 && objRank < static_cast<int>( m_objects.size() ));
- return true;
+ m_objects[objRank].transparency = value;
}
-bool CEngine::AddQuick(int objRank, const EngineObjLevel4& buffer,
- std::string tex1Name, std::string tex2Name,
- float min, float max, bool globalUpdate)
+void CEngine::GetObjectBBox(int objRank, Math::Vector& min, Math::Vector& max)
{
- if ( objRank < 0 || objRank >= static_cast<int>( m_objects.size() ) )
- {
- GetLogger()->Error("AddQuick(): invalid object rank %d\n", objRank);
- return false;
- }
+ assert(objRank >= 0 && objRank < static_cast<int>( m_objects.size() ));
- EngineObjLevel1& p1 = AddLevel1(tex1Name, tex2Name);
- EngineObjLevel2& p2 = AddLevel2(p1, objRank);
- EngineObjLevel3& p3 = AddLevel3(p2, min, max);
+ int baseObjRank = m_objects[objRank].baseObjRank;
+ if (baseObjRank == -1)
+ return;
- p3.next.push_back(buffer);
- p3.next.back().used = true; // ensure that it is used
+ assert(baseObjRank >= 0 && baseObjRank < static_cast<int>(m_baseObjects.size()));
- if (globalUpdate)
- {
- m_updateGeometry = true;
- }
- else
- {
- for (int i = 0; i < static_cast<int>( buffer.vertices.size() ); i++)
- {
- m_objects[objRank].bboxMin.x = Math::Min(buffer.vertices[i].coord.x, m_objects[objRank].bboxMin.x);
- m_objects[objRank].bboxMin.y = Math::Min(buffer.vertices[i].coord.y, m_objects[objRank].bboxMin.y);
- m_objects[objRank].bboxMin.z = Math::Min(buffer.vertices[i].coord.z, m_objects[objRank].bboxMin.z);
- m_objects[objRank].bboxMax.x = Math::Max(buffer.vertices[i].coord.x, m_objects[objRank].bboxMax.x);
- m_objects[objRank].bboxMax.y = Math::Max(buffer.vertices[i].coord.y, m_objects[objRank].bboxMax.y);
- m_objects[objRank].bboxMax.z = Math::Max(buffer.vertices[i].coord.z, m_objects[objRank].bboxMax.z);
- }
+ min = m_baseObjects[baseObjRank].bboxMin;
+ max = m_baseObjects[baseObjRank].bboxMax;
+}
- m_objects[objRank].radius = Math::Max(m_objects[objRank].bboxMin.Length(),
- m_objects[objRank].bboxMax.Length());
- }
- if (buffer.type == ENG_TRIANGLE_TYPE_TRIANGLES)
- m_objects[objRank].totalTriangles += buffer.vertices.size() / 3;
- else if (buffer.type == ENG_TRIANGLE_TYPE_SURFACE)
- m_objects[objRank].totalTriangles += buffer.vertices.size() - 2;
+int CEngine::GetObjectTotalTriangles(int objRank)
+{
+ assert(objRank >= 0 && objRank < static_cast<int>( m_objects.size() ));
- return true;
+ int baseObjRank = m_objects[objRank].baseObjRank;
+ if (baseObjRank == -1)
+ return 0;
+
+ assert(baseObjRank >= 0 && baseObjRank < static_cast<int>( m_baseObjects.size() ));
+
+ return m_baseObjects[baseObjRank].totalTriangles;
}
-EngineObjLevel4* CEngine::FindTriangles(int objRank, const Material& material,
- int state, std::string tex1Name,
- std::string tex2Name, float min, float max)
+EngineBaseObjDataTier* CEngine::FindTriangles(int objRank, const Material& material,
+ int state, std::string tex1Name,
+ std::string tex2Name, float min, float max)
{
- if ( objRank < 0 || objRank >= static_cast<int>( m_objects.size() ) )
- {
- GetLogger()->Error("FindTriangles(): invalid object rank %d\n", objRank);
+ assert(objRank >= 0 && objRank < static_cast<int>( m_objects.size() ));
+
+ int baseObjRank = m_objects[objRank].baseObjRank;
+ if (baseObjRank == -1)
return nullptr;
- }
- for (int l1 = 0; l1 < static_cast<int>( m_objectTree.size() ); l1++)
+ assert(baseObjRank >= 0 && baseObjRank < static_cast<int>( m_baseObjects.size() ));
+
+ EngineBaseObject& p1 = m_baseObjects[baseObjRank];
+
+ for (int l2 = 0; l2 < static_cast<int>( p1.next.size() ); l2++)
{
- EngineObjLevel1& p1 = m_objectTree[l1];
- if (! p1.used) continue;
+ EngineBaseObjTexTier& p2 = p1.next[l2];
- if (p1.tex1Name != tex1Name) continue;
- // TODO: tex2Name compare?
+ if (p2.tex1Name != tex1Name)
+ continue;
- for (int l2 = 0; l2 < static_cast<int>( p1.next.size() ); l2++)
+ for (int l3 = 0; l3 < static_cast<int>( p2.next.size() ); l3++)
{
- EngineObjLevel2& p2 = p1.next[l2];
- if (! p2.used) continue;
+ EngineBaseObjLODTier& p3 = p2.next[l3];
- if (p2.objRank != objRank) continue;
+ if (p3.min != min || p3.max != max)
+ continue;
- for (int l3 = 0; l3 < static_cast<int>( p2.next.size() ); l3++)
+ for (int l4 = 0; l4 < static_cast<int>( p3.next.size() ); l4++)
{
- EngineObjLevel3& p3 = p2.next[l3];
- if (! p3.used) continue;
-
- if (p3.min != min || p3.max != max) continue;
-
- for (int l4 = 0; l4 < static_cast<int>( p3.next.size() ); l4++)
- {
- EngineObjLevel4& p4 = p3.next[l4];
- if (! p4.used) continue;
+ EngineBaseObjDataTier& p4 = p3.next[l4];
- if ( (p4.state & (~(ENG_RSTATE_DUAL_BLACK|ENG_RSTATE_DUAL_WHITE))) != state ||
- p4.material != material )
- continue;
+ if ( (p4.state & (~(ENG_RSTATE_DUAL_BLACK|ENG_RSTATE_DUAL_WHITE))) != state ||
+ p4.material != material )
+ continue;
- return &p4;
- }
+ return &p4;
}
}
}
@@ -1001,91 +840,85 @@ EngineObjLevel4* CEngine::FindTriangles(int objRank, const Material& material,
}
int CEngine::GetPartialTriangles(int objRank, float min, float max, float percent, int maxCount,
- std::vector<EngineTriangle>& triangles)
+ std::vector<EngineTriangle>& triangles)
{
- if ( objRank < 0 || objRank >= static_cast<int>( m_objects.size() ) )
- {
- GetLogger()->Error("GetPartialTriangles(): invalid object rank %d\n", objRank);
+ assert(objRank >= 0 && objRank < static_cast<int>( m_objects.size() ));
+
+ int baseObjRank = m_objects[objRank].baseObjRank;
+ if (baseObjRank == -1)
return 0;
- }
- int total = m_objects[objRank].totalTriangles;
+ assert(baseObjRank >= 0 && baseObjRank < static_cast<int>( m_baseObjects.size() ));
+
+ EngineBaseObject& p1 = m_baseObjects[baseObjRank];
+
+ int total = p1.totalTriangles;
int expectedCount = static_cast<int>(percent * total);
triangles.reserve(Math::Min(maxCount, expectedCount));
int actualCount = 0;
- for (int l1 = 0; l1 < static_cast<int>( m_objectTree.size() ); l1++)
+ for (int l2 = 0; l2 < static_cast<int>( p1.next.size() ); l2++)
{
- EngineObjLevel1& p1 = m_objectTree[l1];
- if (! p1.used) continue;
+ EngineBaseObjTexTier& p2 = p1.next[l2];
- for (int l2 = 0; l2 < static_cast<int>( p1.next.size() ); l2++)
+ for (int l3 = 0; l3 < static_cast<int>( p2.next.size() ); l3++)
{
- EngineObjLevel2& p2 = p1.next[l2];
- if (! p2.used) continue;
+ EngineBaseObjLODTier& p3 = p2.next[l3];
- if (p2.objRank != objRank) continue;
+ if (p3.min != min || p3.max != max)
+ continue;
- for (int l3 = 0; l3 < static_cast<int>( p2.next.size() ); l3++)
+ for (int l4 = 0; l4 < static_cast<int>( p3.next.size() ); l4++)
{
- EngineObjLevel3& p3 = p2.next[l3];
- if (! p3.used) continue;
+ EngineBaseObjDataTier& p4 = p3.next[l4];
- if (p3.min != min || p3.max != max) continue;
-
- for (int l4 = 0; l4 < static_cast<int>( p3.next.size() ); l4++)
+ if (p4.type == ENG_TRIANGLE_TYPE_TRIANGLES)
{
- EngineObjLevel4& p4 = p3.next[l4];
- if (! p4.used) continue;
-
- if (p4.type == ENG_TRIANGLE_TYPE_TRIANGLES)
+ for (int i = 0; i < static_cast<int>( p4.vertices.size() ); i += 3)
{
- for (int i = 0; i < static_cast<int>( p4.vertices.size() ); i += 3)
- {
- if (static_cast<float>(actualCount) / total >= percent)
- break;
+ if (static_cast<float>(actualCount) / total >= percent)
+ break;
- if (actualCount >= maxCount)
- break;
+ if (actualCount >= maxCount)
+ break;
- EngineTriangle t;
- t.triangle[0] = p4.vertices[i];
- t.triangle[1] = p4.vertices[i+1];
- t.triangle[2] = p4.vertices[i+2];
- t.material = p4.material;
- t.state = p4.state;
- t.tex1Name = p1.tex1Name;
- t.tex2Name = p1.tex2Name;
+ EngineTriangle t;
+ t.triangle[0] = p4.vertices[i];
+ t.triangle[1] = p4.vertices[i+1];
+ t.triangle[2] = p4.vertices[i+2];
+ t.material = p4.material;
+ t.state = p4.state;
+ t.tex1Name = p2.tex1Name;
+ t.tex2Name = p2.tex2Name;
- triangles.push_back(t);
+ triangles.push_back(t);
- ++actualCount;
- }
+ ++actualCount;
}
- else if (p4.type == ENG_TRIANGLE_TYPE_SURFACE)
+ }
+ else if (p4.type == ENG_TRIANGLE_TYPE_SURFACE)
+ {
+ for (int i = 0; i < static_cast<int>( p4.vertices.size() ); i += 1)
{
- for (int i = 0; i < static_cast<int>( p4.vertices.size() ); i += 1)
- {
- if (static_cast<float>(actualCount) / total >= percent)
- break;
+ if (static_cast<float>(actualCount) / total >= percent)
+ break;
- if (actualCount >= maxCount)
- break;
+ if (actualCount >= maxCount)
+ break;
- EngineTriangle t;
- t.triangle[0] = p4.vertices[i];
- t.triangle[1] = p4.vertices[i+1];
- t.triangle[2] = p4.vertices[i+2];
- t.material = p4.material;
- t.state = p4.state;
- t.tex1Name = p1.tex1Name;
- t.tex2Name = p1.tex2Name;
+ EngineTriangle t;
+ t.triangle[0] = p4.vertices[i];
+ t.triangle[1] = p4.vertices[i+1];
+ t.triangle[2] = p4.vertices[i+2];
+ t.material = p4.material;
+ t.state = p4.state;
+ t.tex1Name = p2.tex1Name;
+ t.tex2Name = p2.tex2Name;
- triangles.push_back(t);
+ triangles.push_back(t);
- ++actualCount;
- }
+ ++actualCount;
}
}
}
@@ -1112,20 +945,20 @@ void CEngine::ChangeLOD()
float oldTerrain = m_terrainVision * m_lastClippingDistance;
float newTerrain = m_terrainVision * m_clippingDistance;
- for (int l1 = 0; l1 < static_cast<int>( m_objectTree.size() ); l1++)
+ for (int baseObjRank = 0; baseObjRank < static_cast<int>( m_baseObjects.size() ); baseObjRank++)
{
- EngineObjLevel1& p1 = m_objectTree[l1];
- if (! p1.used) continue;
+ EngineBaseObject& p1 = m_baseObjects[baseObjRank];
+
+ if (! p1.used)
+ continue;
for (int l2 = 0; l2 < static_cast<int>( p1.next.size() ); l2++)
{
- EngineObjLevel2& p2 = p1.next[l2];
- if (! p2.used) continue;
+ EngineBaseObjTexTier& p2 = p1.next[l2];
for (int l3 = 0; l3 < static_cast<int>( p2.next.size() ); l3++)
{
- EngineObjLevel3& p3 = p2.next[l3];
- if (! p3.used) continue;
+ EngineBaseObjLODTier& p3 = p2.next[l3];
if ( Math::IsEqual(p3.min, 0.0f ) &&
Math::IsEqual(p3.max, oldLimit[0]) )
@@ -1157,43 +990,40 @@ void CEngine::ChangeLOD()
m_lastClippingDistance = m_clippingDistance;
}
-bool CEngine::ChangeSecondTexture(int objRank, const std::string& tex2Name)
+void CEngine::ChangeSecondTexture(int objRank, const std::string& tex2Name)
{
- for (int l1 = 0; l1 < static_cast<int>( m_objectTree.size() ); l1++)
- {
- EngineObjLevel1& p1 = m_objectTree[l1];
- if (! p1.used) continue;
-
- if (p1.tex2Name == tex2Name) continue; // already new
+ assert(objRank >= 0 && objRank < static_cast<int>( m_objects.size() ));
- for (int l2 = 0; l2 < static_cast<int>( p1.next.size() ); l2++)
- {
- EngineObjLevel2& p2 = p1.next[l2];
- if (! p2.used) continue;
+ int baseObjRank = m_objects[objRank].baseObjRank;
+ if (baseObjRank == -1)
+ return;
- if (p2.objRank != objRank) continue;
+ assert(baseObjRank >= 0 && baseObjRank < static_cast<int>( m_baseObjects.size() ));
- EngineObjLevel1& newP1 = AddLevel1(p1.tex1Name, tex2Name);
+ EngineBaseObject& p1 = m_baseObjects[baseObjRank];
- newP1.next.push_back(EngineObjLevel2(true, objRank));
+ for (int l2 = 0; l2 < static_cast<int>( p1.next.size() ); l2++)
+ {
+ EngineBaseObjTexTier& p2 = p1.next[l2];
- EngineObjLevel2& newP2 = newP1.next.back();
- newP2.next.swap(p2.next);
+ if (p2.tex2Name == tex2Name)
+ continue; // already new
- p2.used = false;
- }
+ EngineBaseObjTexTier& newP2 = AddLevel2(p1, p2.tex1Name, tex2Name);
+ newP2.next.swap(p2.next);
}
- return true;
}
-bool CEngine::ChangeTextureMapping(int objRank, const Material& mat, int state,
- const std::string& tex1Name, const std::string& tex2Name,
- float min, float max, EngineTextureMapping mode,
- float au, float bu, float av, float bv)
+void CEngine::ChangeTextureMapping(int objRank, const Material& mat, int state,
+ const std::string& tex1Name, const std::string& tex2Name,
+ float min, float max, EngineTextureMapping mode,
+ float au, float bu, float av, float bv)
{
- EngineObjLevel4* p4 = FindTriangles(objRank, mat, state, tex1Name, tex2Name, min, max);
+ assert(objRank >= 0 && objRank < static_cast<int>( m_objects.size() ));
+
+ EngineBaseObjDataTier* p4 = FindTriangles(objRank, mat, state, tex1Name, tex2Name, min, max);
if (p4 == nullptr)
- return false;
+ return;
int nb = p4->vertices.size();
@@ -1243,27 +1073,113 @@ bool CEngine::ChangeTextureMapping(int objRank, const Material& mat, int state,
}
}
- return true;
+ UpdateStaticBuffer(*p4);
}
-bool CEngine::TrackTextureMapping(int objRank, const Material& mat, int state,
- const std::string& tex1Name, const std::string& tex2Name,
- float min, float max, EngineTextureMapping mode,
- float pos, float factor, float tl, float ts, float tt)
+void CEngine::TrackTextureMapping(int objRank, const Material& mat, int state,
+ const std::string& tex1Name, const std::string& tex2Name,
+ float min, float max, EngineTextureMapping mode,
+ float pos, float factor, float tl, float ts, float tt)
{
- // TODO track texture mapping: pretty complex code, so leaving it for now
- GetLogger()->Trace("CEngine::TrackTextureMapping(): stub!\n");
- return true;
+ assert(objRank >= 0 && objRank < static_cast<int>( m_objects.size() ));
+
+ EngineBaseObjDataTier* p4 = FindTriangles(objRank, mat, state, tex1Name, tex2Name, min, max);
+ if (p4 == nullptr)
+ return;
+
+ int tNum = p4->vertices.size();
+ if (tNum < 12 || tNum % 6 != 0)
+ return;
+
+ std::vector<Gfx::VertexTex2>& vs = p4->vertices;
+
+ while (pos < 0.0f)
+ pos += 1.0f; // never negative!
+
+ Math::Vector current;
+
+ for (int i = 0; i < 6; i++)
+ {
+ for (int j = 0; j < 6; j++)
+ {
+ if (Math::IsEqual(vs[i].coord.x, vs[j+6].coord.x) &&
+ Math::IsEqual(vs[i].coord.y, vs[j+6].coord.y))
+ {
+ current.x = vs[i].coord.x; // position end link
+ current.y = vs[i].coord.y;
+ break;
+ }
+ }
+ }
+
+ float ps = 0.0f; // start position on the periphery
+ float pe = 0.0f;
+ int is[6] = { 0 }, ie[6] = { 0 };
+
+ int tBase = 0;
+ for (int ti = 0; ti < tNum / 6; ti++)
+ {
+ int s = 0;
+ int e = 0;
+
+ for (int i = 0; i < 6; i++)
+ {
+ if (Math::IsEqual(vs[tBase + i].coord.x, current.x, 0.0001f) &&
+ Math::IsEqual(vs[tBase + i].coord.y, current.y, 0.0001f))
+ {
+ ie[e++] = i;
+ }
+ else
+ {
+ is[s++] = i;
+ }
+ }
+ if (s == 3 && e == 3)
+ {
+ pe = ps + Math::Point(vs[tBase + is[0]].coord.x - vs[tBase + ie[0]].coord.x,
+ vs[tBase + is[0]].coord.y - vs[tBase + ie[0]].coord.y).Length() / factor; // end position on the periphery
+
+ float pps = ps + pos;
+ float ppe = pe + pos;
+ int offset = static_cast<int>(pps);
+ ppe -= offset;
+ pps -= offset;
+
+ for (int i = 0; i < 3; i++)
+ {
+ vs[tBase + is[i]].texCoord.x = ((pps * tl) + ts) / tt;
+ vs[tBase + ie[i]].texCoord.x = ((ppe * tl) + ts) / tt;
+ }
+ }
+
+ if (ti >= (tNum / 6) - 1)
+ break;
+
+ for (int i = 0; i < 6; i++)
+ {
+ if (!Math::IsEqual(vs[tBase + i+6].coord.x, current.x, 0.0001f) ||
+ !Math::IsEqual(vs[tBase + i+6].coord.y, current.y, 0.0001f))
+ {
+ current.x = vs[tBase + i+6].coord.x; // end next link
+ current.y = vs[tBase + i+6].coord.y;
+ break;
+ }
+ }
+ ps = pe; // following start position on the periphery
+ tBase += 6;
+ }
+
+ UpdateStaticBuffer(*p4);
}
-bool CEngine::CreateShadow(int objRank)
+void CEngine::CreateShadow(int objRank)
{
- if ( objRank < 0 || objRank >= static_cast<int>( m_objects.size() ) )
- return false;
+ assert(objRank >= 0 && objRank < static_cast<int>( m_objects.size() ));
// Already allocated?
- if (m_objects[objRank].shadowRank != -1) return true;
+ if (m_objects[objRank].shadowRank != -1)
+ return;
int index = 0;
for ( ; index < static_cast<int>( m_shadows.size() ); index++)
@@ -1275,146 +1191,147 @@ bool CEngine::CreateShadow(int objRank)
}
}
- m_shadows.push_back(EngineShadow());
+ if (index == static_cast<int>( m_shadows.size() ))
+ m_shadows.push_back(EngineShadow());
m_shadows[index].used = true;
m_shadows[index].objRank = objRank;
m_shadows[index].height = 0.0f;
m_objects[objRank].shadowRank = index;
-
- return true;
}
void CEngine::DeleteShadow(int objRank)
{
- if ( objRank < 0 || objRank >= static_cast<int>( m_objects.size() ) )
- return;
+ assert(objRank >= 0 && objRank < static_cast<int>( m_objects.size() ));
- int i = m_objects[objRank].shadowRank;
- if (i == -1)
+ int shadowRank = m_objects[objRank].shadowRank;
+ if (shadowRank == -1)
return;
- m_shadows[i].used = false;
- m_shadows[i].objRank = -1;
+ assert(shadowRank >= 0 && shadowRank < static_cast<int>( m_shadows.size() ));
+
+ m_shadows[shadowRank].used = false;
+ m_shadows[shadowRank].objRank = -1;
m_objects[objRank].shadowRank = -1;
}
-bool CEngine::SetObjectShadowHide(int objRank, bool hide)
+void CEngine::SetObjectShadowHide(int objRank, bool hide)
{
- if ( objRank < 0 || objRank >= static_cast<int>( m_objects.size() ) )
- return false;
+ assert(objRank >= 0 && objRank < static_cast<int>( m_objects.size() ));
- int i = m_objects[objRank].shadowRank;
- if (i == -1)
- return false;
+ int shadowRank = m_objects[objRank].shadowRank;
+ if (shadowRank == -1)
+ return;
- m_shadows[i].hide = hide;
- return true;
+ assert(shadowRank >= 0 && shadowRank < static_cast<int>( m_shadows.size() ));
+
+ m_shadows[shadowRank].hide = hide;
}
-bool CEngine::SetObjectShadowType(int objRank, EngineShadowType type)
+void CEngine::SetObjectShadowType(int objRank, EngineShadowType type)
{
- if ( objRank < 0 || objRank >= static_cast<int>( m_objects.size() ) )
- return false;
+ assert(objRank >= 0 && objRank < static_cast<int>( m_objects.size() ));
- int i = m_objects[objRank].shadowRank;
- if (i == -1)
- return false;
+ int shadowRank = m_objects[objRank].shadowRank;
+ if (shadowRank == -1)
+ return;
- m_shadows[i].type = type;
- return true;
+ assert(shadowRank >= 0 && shadowRank < static_cast<int>( m_shadows.size() ));
+
+ m_shadows[shadowRank].type = type;
}
-bool CEngine::SetObjectShadowPos(int objRank, const Math::Vector& pos)
+void CEngine::SetObjectShadowPos(int objRank, const Math::Vector& pos)
{
- if ( objRank < 0 || objRank >= static_cast<int>( m_objects.size() ) )
- return false;
+ assert(objRank >= 0 && objRank < static_cast<int>( m_objects.size() ));
- int i = m_objects[objRank].shadowRank;
- if (i == -1)
- return false;
+ int shadowRank = m_objects[objRank].shadowRank;
+ if (shadowRank == -1)
+ return;
- m_shadows[i].pos = pos;
- return true;
+ assert(shadowRank >= 0 && shadowRank < static_cast<int>( m_shadows.size() ));
+
+ m_shadows[shadowRank].pos = pos;
}
-bool CEngine::SetObjectShadowNormal(int objRank, const Math::Vector& normal)
+void CEngine::SetObjectShadowNormal(int objRank, const Math::Vector& normal)
{
- if ( objRank < 0 || objRank >= static_cast<int>( m_objects.size() ) )
- return false;
+ assert(objRank >= 0 && objRank < static_cast<int>( m_objects.size() ));
- int i = m_objects[objRank].shadowRank;
- if (i == -1)
- return false;
+ int shadowRank = m_objects[objRank].shadowRank;
+ if (shadowRank == -1)
+ return;
- m_shadows[i].normal = normal;
- return true;
+ assert(shadowRank >= 0 && shadowRank < static_cast<int>( m_shadows.size() ));
+
+ m_shadows[shadowRank].normal = normal;
}
-bool CEngine::SetObjectShadowAngle(int objRank, float angle)
+void CEngine::SetObjectShadowAngle(int objRank, float angle)
{
- if ( objRank < 0 || objRank >= static_cast<int>( m_objects.size() ) )
- return false;
+ assert(objRank >= 0 && objRank < static_cast<int>( m_objects.size() ));
- int i = m_objects[objRank].shadowRank;
- if (i == -1)
- return false;
+ int shadowRank = m_objects[objRank].shadowRank;
+ if (shadowRank == -1)
+ return;
- m_shadows[i].angle = angle;
- return true;
+ assert(shadowRank >= 0 && shadowRank < static_cast<int>( m_shadows.size() ));
+
+ m_shadows[shadowRank].angle = angle;
}
-bool CEngine::SetObjectShadowRadius(int objRank, float radius)
+void CEngine::SetObjectShadowRadius(int objRank, float radius)
{
- if ( objRank < 0 || objRank >= static_cast<int>( m_objects.size() ) )
- return false;
+ assert(objRank >= 0 && objRank < static_cast<int>( m_objects.size() ));
- int i = m_objects[objRank].shadowRank;
- if (i == -1)
- return false;
+ int shadowRank = m_objects[objRank].shadowRank;
+ if (shadowRank == -1)
+ return;
- m_shadows[i].radius = radius;
- return true;
+ assert(shadowRank >= 0 && shadowRank < static_cast<int>( m_shadows.size() ));
+
+ m_shadows[shadowRank].radius = radius;
}
-bool CEngine::SetObjectShadowIntensity(int objRank, float intensity)
+void CEngine::SetObjectShadowIntensity(int objRank, float intensity)
{
- if ( objRank < 0 || objRank >= static_cast<int>( m_objects.size() ) )
- return false;
+ assert(objRank >= 0 && objRank < static_cast<int>( m_objects.size() ));
- int i = m_objects[objRank].shadowRank;
- if (i == -1)
- return false;
+ int shadowRank = m_objects[objRank].shadowRank;
+ if (shadowRank == -1)
+ return;
- m_shadows[i].intensity = intensity;
- return true;
+ assert(shadowRank >= 0 && shadowRank < static_cast<int>( m_shadows.size() ));
+
+ m_shadows[shadowRank].intensity = intensity;
}
-bool CEngine::SetObjectShadowHeight(int objRank, float height)
+void CEngine::SetObjectShadowHeight(int objRank, float height)
{
- if ( objRank < 0 || objRank >= static_cast<int>( m_objects.size() ) )
- return false;
+ assert(objRank >= 0 && objRank < static_cast<int>( m_objects.size() ));
- int i = m_objects[objRank].shadowRank;
- if (i == -1)
- return false;
+ int shadowRank = m_objects[objRank].shadowRank;
+ if (shadowRank == -1)
+ return;
- m_shadows[i].height = height;
- return true;
+ assert(shadowRank >= 0 && shadowRank < static_cast<int>( m_shadows.size() ));
+
+ m_shadows[shadowRank].height = height;
}
float CEngine::GetObjectShadowRadius(int objRank)
{
- if ( objRank < 0 || objRank >= static_cast<int>( m_objects.size() ) )
- return 0.0f;
+ assert(objRank >= 0 && objRank < static_cast<int>( m_objects.size() ));
- int i = m_objects[objRank].shadowRank;
- if (i == -1)
+ int shadowRank = m_objects[objRank].shadowRank;
+ if (shadowRank == -1)
return 0.0f;
- return m_shadows[i].radius;
+ assert(shadowRank >= 0 && shadowRank < static_cast<int>( m_shadows.size() ));
+
+ return m_shadows[shadowRank].radius;
}
bool CEngine::GetHighlight(Math::Point &p1, Math::Point &p2)
@@ -1436,21 +1353,31 @@ void CEngine::SetHighlightRank(int *rankList)
bool CEngine::GetBBox2D(int objRank, Math::Point &min, Math::Point &max)
{
+ assert(objRank >= 0 && objRank < static_cast<int>( m_objects.size() ));
+
min.x = 1000000.0f;
min.y = 1000000.0f;
max.x = -1000000.0f;
max.y = -1000000.0f;
+ int baseObjRank = m_objects[objRank].baseObjRank;
+ if (baseObjRank == -1)
+ return false;
+
+ assert(baseObjRank >= 0 && baseObjRank < static_cast<int>( m_baseObjects.size() ));
+
+ EngineBaseObject& p1 = m_baseObjects[baseObjRank];
+
for (int i = 0; i < 8; i++)
{
Math::Vector p;
- if ( i & (1<<0) ) p.x = m_objects[objRank].bboxMin.x;
- else p.x = m_objects[objRank].bboxMax.x;
- if ( i & (1<<1) ) p.y = m_objects[objRank].bboxMin.y;
- else p.y = m_objects[objRank].bboxMax.y;
- if ( i & (1<<2) ) p.z = m_objects[objRank].bboxMin.z;
- else p.z = m_objects[objRank].bboxMax.z;
+ if ( i & (1<<0) ) p.x = p1.bboxMin.x;
+ else p.x = p1.bboxMax.x;
+ if ( i & (1<<1) ) p.y = p1.bboxMin.y;
+ else p.y = p1.bboxMax.y;
+ if ( i & (1<<2) ) p.z = p1.bboxMin.z;
+ else p.z = p1.bboxMax.z;
Math::Vector pp;
if (TransformPoint(pp, objRank, p))
@@ -1462,20 +1389,36 @@ bool CEngine::GetBBox2D(int objRank, Math::Point &min, Math::Point &max)
}
}
- if ( min.x == 1000000.0f ||
- min.y == 1000000.0f ||
- max.x == -1000000.0f ||
- max.y == -1000000.0f ) return false;
+ if (min.x == 1000000.0f ||
+ min.y == 1000000.0f ||
+ max.x == -1000000.0f ||
+ max.y == -1000000.0f)
+ return false;
return true;
}
-void CEngine::FlushGroundSpot()
+void CEngine::DeleteAllGroundSpots()
{
m_groundSpots.clear();
m_firstGroundSpot = true;
- // TODO: blank all shadow textures
+ for (int s = 0; s < 16; s++)
+ {
+ CImage shadowImg(Math::IntPoint(256, 256));
+ shadowImg.Fill(Gfx::IntColor(255, 255, 255, 255));
+
+ std::stringstream str;
+ str << "shadow" << std::setfill('0') << std::setw(2) << s << ".png";
+ std::string texName = str.str();
+
+ DeleteTexture(texName);
+
+ Gfx::Texture tex = m_device->CreateTexture(&shadowImg, m_defaultTexParams);
+
+ m_texNameMap[texName] = tex;
+ m_revTexNameMap[tex] = texName;
+ }
}
int CEngine::CreateGroundSpot()
@@ -1500,54 +1443,46 @@ int CEngine::CreateGroundSpot()
void CEngine::DeleteGroundSpot(int rank)
{
+ assert(rank >= 0 && rank < static_cast<int>( m_groundSpots.size() ));
+
m_groundSpots[rank].used = false;
m_groundSpots[rank].pos = Math::Vector(0.0f, 0.0f, 0.0f);
}
-bool CEngine::SetObjectGroundSpotPos(int rank, const Math::Vector& pos)
+void CEngine::SetObjectGroundSpotPos(int rank, const Math::Vector& pos)
{
- if ( rank < 0 || rank >= static_cast<int>( m_groundSpots.size() ) )
- return 0.0f;
+ assert(rank >= 0 && rank < static_cast<int>( m_groundSpots.size() ));
m_groundSpots[rank].pos = pos;
- return true;
}
-bool CEngine::SetObjectGroundSpotRadius(int rank, float radius)
+void CEngine::SetObjectGroundSpotRadius(int rank, float radius)
{
- if ( rank < 0 || rank >= static_cast<int>( m_groundSpots.size() ) )
- return 0.0f;
+ assert(rank >= 0 && rank < static_cast<int>( m_groundSpots.size() ));
m_groundSpots[rank].radius = radius;
- return true;
}
-bool CEngine::SetObjectGroundSpotColor(int rank, const Color& color)
+void CEngine::SetObjectGroundSpotColor(int rank, const Color& color)
{
- if ( rank < 0 || rank >= static_cast<int>( m_groundSpots.size() ) )
- return 0.0f;
+ assert(rank >= 0 && rank < static_cast<int>( m_groundSpots.size() ));
m_groundSpots[rank].color = color;
- return true;
}
-bool CEngine::SetObjectGroundSpotMinMax(int rank, float min, float max)
+void CEngine::SetObjectGroundSpotMinMax(int rank, float min, float max)
{
- if ( rank < 0 || rank >= static_cast<int>( m_groundSpots.size() ) )
- return 0.0f;
+ assert(rank >= 0 && rank < static_cast<int>( m_groundSpots.size() ));
m_groundSpots[rank].min = min;
m_groundSpots[rank].max = max;
- return true;
}
-bool CEngine::SetObjectGroundSpotSmooth(int rank, float smooth)
+void CEngine::SetObjectGroundSpotSmooth(int rank, float smooth)
{
- if ( rank < 0 || rank >= static_cast<int>( m_groundSpots.size() ) )
- return 0.0f;
+ assert(rank >= 0 && rank < static_cast<int>( m_groundSpots.size() ));
m_groundSpots[rank].smooth = smooth;
- return true;
}
void CEngine::CreateGroundMark(Math::Vector pos, float radius,
@@ -1556,6 +1491,7 @@ void CEngine::CreateGroundMark(Math::Vector pos, float radius,
{
m_groundMark.LoadDefault();
+ m_groundMark.draw = true;
m_groundMark.phase = ENG_GR_MARK_PHASE_INC;
m_groundMark.delay[0] = delay1;
m_groundMark.delay[1] = delay2;
@@ -1575,8 +1511,6 @@ void CEngine::DeleteGroundMark(int rank)
void CEngine::ComputeDistance()
{
- // TODO: s_resol???
-
for (int i = 0; i < static_cast<int>( m_objects.size() ); i++)
{
if (! m_objects[i].used)
@@ -1595,51 +1529,39 @@ void CEngine::UpdateGeometry()
if (! m_updateGeometry)
return;
- for (int i = 0; i < static_cast<int>( m_objects.size() ); i++)
+ for (int baseObjRank = 0; baseObjRank < static_cast<int>( m_baseObjects.size() ); baseObjRank++)
{
- m_objects[i].bboxMin.x = 0;
- m_objects[i].bboxMin.y = 0;
- m_objects[i].bboxMin.z = 0;
- m_objects[i].bboxMax.x = 0;
- m_objects[i].bboxMax.y = 0;
- m_objects[i].bboxMax.z = 0;
- m_objects[i].radius = 0;
- }
+ EngineBaseObject &p1 = m_baseObjects[baseObjRank];
+ if (! p1.used)
+ continue;
- for (int l1 = 0; l1 < static_cast<int>( m_objectTree.size() ); l1++)
- {
- EngineObjLevel1& p1 = m_objectTree[l1];
- if (! p1.used) continue;
+ p1.bboxMin.LoadZero();
+ p1.bboxMax.LoadZero();
+ p1.radius = 0;
for (int l2 = 0; l2 < static_cast<int>( p1.next.size() ); l2++)
{
- EngineObjLevel2& p2 = p1.next[l2];
- if (! p2.used) continue;
+ EngineBaseObjTexTier& p2 = p1.next[l2];
for (int l3 = 0; l3 < static_cast<int>( p2.next.size() ); l3++)
{
- EngineObjLevel3& p3 = p2.next[l3];
- if (! p3.used) continue;
+ EngineBaseObjLODTier& p3 = p2.next[l3];
for (int l4 = 0; l4 < static_cast<int>( p3.next.size() ); l4++)
{
- EngineObjLevel4& p4 = p3.next[l4];
- if (! p4.used) continue;
-
- int objRank = p2.objRank;
+ EngineBaseObjDataTier& p4 = p3.next[l4];
for (int i = 0; i < static_cast<int>( p4.vertices.size() ); i++)
{
- m_objects[objRank].bboxMin.x = Math::Min(p4.vertices[i].coord.x, m_objects[objRank].bboxMin.x);
- m_objects[objRank].bboxMin.y = Math::Min(p4.vertices[i].coord.y, m_objects[objRank].bboxMin.y);
- m_objects[objRank].bboxMin.z = Math::Min(p4.vertices[i].coord.z, m_objects[objRank].bboxMin.z);
- m_objects[objRank].bboxMax.x = Math::Max(p4.vertices[i].coord.x, m_objects[objRank].bboxMax.x);
- m_objects[objRank].bboxMax.y = Math::Max(p4.vertices[i].coord.y, m_objects[objRank].bboxMax.y);
- m_objects[objRank].bboxMax.z = Math::Max(p4.vertices[i].coord.z, m_objects[objRank].bboxMax.z);
+ p1.bboxMin.x = Math::Min(p4.vertices[i].coord.x, p1.bboxMin.x);
+ p1.bboxMin.y = Math::Min(p4.vertices[i].coord.y, p1.bboxMin.y);
+ p1.bboxMin.z = Math::Min(p4.vertices[i].coord.z, p1.bboxMin.z);
+ p1.bboxMax.x = Math::Max(p4.vertices[i].coord.x, p1.bboxMax.x);
+ p1.bboxMax.y = Math::Max(p4.vertices[i].coord.y, p1.bboxMax.y);
+ p1.bboxMax.z = Math::Max(p4.vertices[i].coord.z, p1.bboxMax.z);
}
- m_objects[objRank].radius = Math::Max(m_objects[objRank].bboxMin.Length(),
- m_objects[objRank].bboxMax.Length());
+ p1.radius = Math::Max(p1.bboxMin.Length(), p1.bboxMax.Length());
}
}
}
@@ -1648,14 +1570,76 @@ void CEngine::UpdateGeometry()
m_updateGeometry = false;
}
+void CEngine::UpdateStaticBuffer(EngineBaseObjDataTier& p4)
+{
+ PrimitiveType type;
+ if (p4.type == ENG_TRIANGLE_TYPE_TRIANGLES)
+ type = PRIMITIVE_TRIANGLES;
+ else
+ type = PRIMITIVE_TRIANGLE_STRIP;
+
+ if (p4.staticBufferId == 0)
+ p4.staticBufferId = m_device->CreateStaticBuffer(type, &p4.vertices[0], p4.vertices.size());
+ else
+ m_device->UpdateStaticBuffer(p4.staticBufferId, type, &p4.vertices[0], p4.vertices.size());
+
+ p4.updateStaticBuffer = false;
+}
+
+void CEngine::UpdateStaticBuffers()
+{
+ if (!m_updateStaticBuffers)
+ return;
+
+ m_updateStaticBuffers = false;
+
+ for (int baseObjRank = 0; baseObjRank < static_cast<int>( m_baseObjects.size() ); baseObjRank++)
+ {
+ EngineBaseObject& p1 = m_baseObjects[baseObjRank];
+ if (! p1.used)
+ continue;
+
+ for (int l2 = 0; l2 < static_cast<int>( p1.next.size() ); l2++)
+ {
+ EngineBaseObjTexTier& p2 = p1.next[l2];
+
+ for (int l3 = 0; l3 < static_cast<int>( p2.next.size() ); l3++)
+ {
+ EngineBaseObjLODTier& p3 = p2.next[l3];
+
+ for (int l4 = 0; l4 < static_cast<int>( p3.next.size() ); l4++)
+ {
+ EngineBaseObjDataTier& p4 = p3.next[l4];
+
+ if (! p4.updateStaticBuffer)
+ continue;
+
+ UpdateStaticBuffer(p4);
+ }
+ }
+ }
+ }
+}
+
void CEngine::Update()
{
ComputeDistance();
UpdateGeometry();
+ UpdateStaticBuffers();
}
bool CEngine::DetectBBox(int objRank, Math::Point mouse)
{
+ assert(objRank >= 0 && objRank < static_cast<int>(m_objects.size()));
+
+ int baseObjRank = m_objects[objRank].baseObjRank;
+ if (baseObjRank == -1)
+ return false;
+
+ assert(baseObjRank >= 0 && baseObjRank < static_cast<int>(m_baseObjects.size()));
+
+ EngineBaseObject& p1 = m_baseObjects[baseObjRank];
+
Math::Point min, max;
min.x = 1000000.0f;
min.y = 1000000.0f;
@@ -1666,12 +1650,12 @@ bool CEngine::DetectBBox(int objRank, Math::Point mouse)
{
Math::Vector p;
- if ( i & (1<<0) ) p.x = m_objects[objRank].bboxMin.x;
- else p.x = m_objects[objRank].bboxMax.x;
- if ( i & (1<<1) ) p.y = m_objects[objRank].bboxMin.y;
- else p.y = m_objects[objRank].bboxMax.y;
- if ( i & (1<<2) ) p.z = m_objects[objRank].bboxMin.z;
- else p.z = m_objects[objRank].bboxMax.z;
+ if ( i & (1<<0) ) p.x = p1.bboxMin.x;
+ else p.x = p1.bboxMax.x;
+ if ( i & (1<<1) ) p.y = p1.bboxMin.y;
+ else p.y = p1.bboxMax.y;
+ if ( i & (1<<2) ) p.z = p1.bboxMin.z;
+ else p.z = p1.bboxMax.z;
Math::Vector pp;
if ( TransformPoint(pp, objRank, p) )
@@ -1694,41 +1678,51 @@ int CEngine::DetectObject(Math::Point mouse)
float min = 1000000.0f;
int nearest = -1;
- for (int l1 = 0; l1 < static_cast<int>( m_objectTree.size() ); l1++)
+ for (int objRank = 0; objRank < static_cast<int>( m_objects.size() ); objRank++)
{
- EngineObjLevel1& p1 = m_objectTree[l1];
- if (! p1.used) continue;
+ if (! m_objects[objRank].used)
+ continue;
- for (int l2 = 0; l2 < static_cast<int>( p1.next.size() ); l2++)
- {
- EngineObjLevel2& p2 = p1.next[l2];
- if (! p2.used) continue;
+ if (m_objects[objRank].type == ENG_OBJTYPE_TERRAIN)
+ continue;
- if (m_objects[p2.objRank].type == ENG_OBJTYPE_TERRAIN) continue;
+ if (! DetectBBox(objRank, mouse))
+ continue;
- if (! DetectBBox(p2.objRank, mouse)) continue;
+ int baseObjRank = m_objects[objRank].baseObjRank;
+ if (baseObjRank == -1)
+ continue;
+
+ assert(baseObjRank >= 0 && baseObjRank < static_cast<int>(m_baseObjects.size()));
+
+ EngineBaseObject& p1 = m_baseObjects[baseObjRank];
+ if (! p1.used)
+ continue;
+
+ for (int l2 = 0; l2 < static_cast<int>( p1.next.size() ); l2++)
+ {
+ EngineBaseObjTexTier& p2 = p1.next[l2];
for (int l3 = 0; l3 < static_cast<int>( p2.next.size() ); l3++)
{
- EngineObjLevel3& p3 = p2.next[l3];
- if (! p3.used) continue;
+ EngineBaseObjLODTier& p3 = p2.next[l3];
- if (p3.min != 0.0f) continue; // LOD B or C?
+ if (p3.min != 0.0f)
+ continue; // LOD B or C?
for (int l4 = 0; l4 < static_cast<int>( p3.next.size() ); l4++)
{
- EngineObjLevel4& p4 = p3.next[l4];
- if (! p4.used) continue;
+ EngineBaseObjDataTier& p4 = p3.next[l4];
if (p4.type == ENG_TRIANGLE_TYPE_TRIANGLES)
{
for (int i = 0; i < static_cast<int>( p4.vertices.size() ); i += 3)
{
float dist = 0.0f;
- if (DetectTriangle(mouse, &p4.vertices[i], p2.objRank, dist) && dist < min)
+ if (DetectTriangle(mouse, &p4.vertices[i], objRank, dist) && dist < min)
{
min = dist;
- nearest = p2.objRank;
+ nearest = objRank;
}
}
}
@@ -1737,10 +1731,10 @@ int CEngine::DetectObject(Math::Point mouse)
for (int i = 0; i < static_cast<int>( p4.vertices.size() ) - 2; i += 1)
{
float dist = 0.0f;
- if (DetectTriangle(mouse, &p4.vertices[i], p2.objRank, dist) && dist < min)
+ if (DetectTriangle(mouse, &p4.vertices[i], objRank, dist) && dist < min)
{
min = dist;
- nearest = p2.objRank;
+ nearest = objRank;
}
}
}
@@ -1754,6 +1748,8 @@ int CEngine::DetectObject(Math::Point mouse)
bool CEngine::DetectTriangle(Math::Point mouse, VertexTex2* triangle, int objRank, float& dist)
{
+ assert(objRank >= 0 && objRank < static_cast<int>(m_objects.size()));
+
Math::Vector p2D[3], p3D;
for (int i = 0; i < 3; i++)
@@ -1766,18 +1762,25 @@ bool CEngine::DetectTriangle(Math::Point mouse, VertexTex2* triangle, int objRan
return false;
}
- if ( mouse.x < p2D[0].x &&
- mouse.x < p2D[1].x &&
- mouse.x < p2D[2].x ) return false;
- if ( mouse.x > p2D[0].x &&
- mouse.x > p2D[1].x &&
- mouse.x > p2D[2].x ) return false;
- if ( mouse.y < p2D[0].y &&
- mouse.y < p2D[1].y &&
- mouse.y < p2D[2].y ) return false;
- if ( mouse.y > p2D[0].y &&
- mouse.y > p2D[1].y &&
- mouse.y > p2D[2].y ) return false;
+ if (mouse.x < p2D[0].x &&
+ mouse.x < p2D[1].x &&
+ mouse.x < p2D[2].x)
+ return false;
+
+ if (mouse.x > p2D[0].x &&
+ mouse.x > p2D[1].x &&
+ mouse.x > p2D[2].x)
+ return false;
+
+ if (mouse.y < p2D[0].y &&
+ mouse.y < p2D[1].y &&
+ mouse.y < p2D[2].y)
+ return false;
+
+ if (mouse.y > p2D[0].y &&
+ mouse.y > p2D[1].y &&
+ mouse.y > p2D[2].y)
+ return false;
Math::Point a, b, c;
a.x = p2D[0].x;
@@ -1794,18 +1797,38 @@ bool CEngine::DetectTriangle(Math::Point mouse, VertexTex2* triangle, int objRan
return true;
}
+//! Use only after world transform already set
bool CEngine::IsVisible(int objRank)
{
- // TODO: use ComputeSphereVisiblity() after tested OK
- return true;
+ assert(objRank >= 0 && objRank < static_cast<int>(m_objects.size()));
+
+ int baseObjRank = m_objects[objRank].baseObjRank;
+ if (baseObjRank == -1)
+ return false;
+
+ assert(baseObjRank >= 0 && baseObjRank < static_cast<int>(m_baseObjects.size()));
+
+ float radius = m_baseObjects[baseObjRank].radius;
+ Math::Vector center(0.0f, 0.0f, 0.0f);
+ if (m_device->ComputeSphereVisibility(center, radius) == Gfx::FRUSTUM_PLANE_ALL)
+ {
+ m_objects[objRank].visible = true;
+ return true;
+ }
+
+ m_objects[objRank].visible = false;
+ return false;
}
bool CEngine::TransformPoint(Math::Vector& p2D, int objRank, Math::Vector p3D)
{
+ assert(objRank >= 0 && objRank < static_cast<int>(m_objects.size()));
+
p3D = Math::Transform(m_objects[objRank].transform, p3D);
p3D = Math::Transform(m_matView, p3D);
- if (p3D.z < 2.0f) return false; // behind?
+ if (p3D.z < 2.0f)
+ return false; // behind?
p2D.x = (p3D.x/p3D.z)*m_matProj.Get(1,1);
p2D.y = (p3D.y/p3D.z)*m_matProj.Get(2,2);
@@ -1855,7 +1878,7 @@ void CEngine::SetState(int state, const Color& color)
params.colorOperation = TEX_MIX_OPER_MODULATE;
params.colorArg1 = TEX_MIX_ARG_TEXTURE;
params.colorArg2 = TEX_MIX_ARG_FACTOR;
- params.alphaOperation = TEX_MIX_OPER_DEFAULT; // TODO: replace with src color ?
+ params.alphaOperation = TEX_MIX_OPER_DEFAULT;
params.factor = color;
m_device->SetTextureEnabled(0, true);
@@ -1874,7 +1897,7 @@ void CEngine::SetState(int state, const Color& color)
params.colorOperation = TEX_MIX_OPER_ADD;
params.colorArg1 = TEX_MIX_ARG_TEXTURE;
params.colorArg2 = TEX_MIX_ARG_FACTOR;
- params.alphaOperation = TEX_MIX_OPER_DEFAULT; // TODO: replace with src color ?
+ params.alphaOperation = TEX_MIX_OPER_DEFAULT;
params.factor = color.Inverse();
m_device->SetTextureEnabled(0, true);
@@ -1914,7 +1937,7 @@ void CEngine::SetState(int state, const Color& color)
TextureStageParams params;
params.colorOperation = TEX_MIX_OPER_REPLACE;
params.colorArg1 = TEX_MIX_ARG_TEXTURE;
- params.alphaOperation = TEX_MIX_OPER_DEFAULT; // TODO: replace with src color ?
+ params.alphaOperation = TEX_MIX_OPER_DEFAULT;
m_device->SetTextureEnabled(0, true);
m_device->SetTextureStageParams(0, params);
@@ -1982,7 +2005,7 @@ void CEngine::SetState(int state, const Color& color)
TextureStageParams params;
params.colorOperation = TEX_MIX_OPER_DEFAULT; // default modulate
- params.alphaOperation = TEX_MIX_OPER_DEFAULT; // TODO: replace with src color ?
+ params.alphaOperation = TEX_MIX_OPER_DEFAULT;
m_device->SetTextureEnabled(0, true);
m_device->SetTextureStageParams(0, params);
@@ -2003,7 +2026,7 @@ void CEngine::SetState(int state, const Color& color)
params.colorOperation = TEX_MIX_OPER_MODULATE;
params.colorArg1 = TEX_MIX_ARG_TEXTURE;
params.colorArg2 = TEX_MIX_ARG_COMPUTED_COLOR;
- params.alphaOperation = TEX_MIX_OPER_DEFAULT; // TODO: ???
+ params.alphaOperation = TEX_MIX_OPER_DEFAULT;
m_device->SetTextureEnabled(1, true);
m_device->SetTextureStageParams(1, params);
}
@@ -2013,7 +2036,7 @@ void CEngine::SetState(int state, const Color& color)
params.colorOperation = TEX_MIX_OPER_ADD;
params.colorArg1 = TEX_MIX_ARG_TEXTURE;
params.colorArg2 = TEX_MIX_ARG_COMPUTED_COLOR;
- params.alphaOperation = TEX_MIX_OPER_DEFAULT; // TODO: ???
+ params.alphaOperation = TEX_MIX_OPER_DEFAULT;
m_device->SetTextureEnabled(1, true);
m_device->SetTextureStageParams(1, params);
}
@@ -2168,42 +2191,50 @@ bool CEngine::LoadAllTextures()
bool ok = true;
- for (int l1 = 0; l1 < static_cast<int>( m_objectTree.size() ); l1++)
+ for (int objRank = 0; objRank < static_cast<int>( m_objects.size() ); objRank++)
{
- EngineObjLevel1& p1 = m_objectTree[l1];
- if (! p1.used) continue;
+ if (! m_objects[objRank].used)
+ continue;
bool terrain = false;
+ if (m_objects[objRank].type == ENG_OBJTYPE_TERRAIN)
+ terrain = true;
- for (int l2 = 0; l2 < static_cast<int>( p1.next.size() ); l2++)
- {
- EngineObjLevel2& p2 = p1.next[l2];
- if (! p2.used) continue;
+ int baseObjRank = m_objects[objRank].baseObjRank;
+ if (baseObjRank == -1)
+ continue;
- if (m_objects[p2.objRank].type == ENG_OBJTYPE_TERRAIN)
- terrain = true;
- }
+ assert(baseObjRank >= 0 && baseObjRank < static_cast<int>( m_baseObjects.size() ));
+
+ EngineBaseObject& p1 = m_baseObjects[baseObjRank];
+ if (! p1.used)
+ continue;
- if (! p1.tex1Name.empty())
+ for (int l2 = 0; l2 < static_cast<int>( p1.next.size() ); l2++)
{
- if (terrain)
- p1.tex1 = LoadTexture(p1.tex1Name, m_terrainTexParams);
- else
- p1.tex1 = LoadTexture(p1.tex1Name);
+ EngineBaseObjTexTier& p2 = p1.next[l2];
- if (! p1.tex1.Valid())
- ok = false;
- }
+ if (! p2.tex1Name.empty())
+ {
+ if (terrain)
+ p2.tex1 = LoadTexture(p2.tex1Name, m_terrainTexParams);
+ else
+ p2.tex1 = LoadTexture(p2.tex1Name);
- if (! p1.tex2Name.empty())
- {
- if (terrain)
- p1.tex2 = LoadTexture(p1.tex2Name, m_terrainTexParams);
- else
- p1.tex2 = LoadTexture(p1.tex2Name);
+ if (! p2.tex1.Valid())
+ ok = false;
+ }
- if (! p1.tex2.Valid())
- ok = false;
+ if (! p2.tex2Name.empty())
+ {
+ if (terrain)
+ p2.tex2 = LoadTexture(p2.tex2Name, m_terrainTexParams);
+ else
+ p2.tex2 = LoadTexture(p2.tex2Name);
+
+ if (! p2.tex2.Valid())
+ ok = false;
+ }
}
}
@@ -2219,7 +2250,8 @@ bool IsExcludeColor(Math::Point *exclude, int x, int y)
if ( x >= static_cast<int>(exclude[i+0].x*256.0f) &&
x < static_cast<int>(exclude[i+1].x*256.0f) &&
y >= static_cast<int>(exclude[i+0].y*256.0f) &&
- y < static_cast<int>(exclude[i+1].y*256.0f) ) return true; // exclude
+ y < static_cast<int>(exclude[i+1].y*256.0f) )
+ return true; // exclude
i += 2;
}
@@ -2235,12 +2267,13 @@ bool CEngine::ChangeTextureColor(const std::string& texName,
Math::Point ts, Math::Point ti,
Math::Point *exclude, float shift, bool hsv)
{
- if ( colorRef1.r == colorNew1.r &&
- colorRef1.g == colorNew1.g &&
- colorRef1.b == colorNew1.b &&
- colorRef2.r == colorNew2.r &&
- colorRef2.g == colorNew2.g &&
- colorRef2.b == colorNew2.b ) return true;
+ if (colorRef1.r == colorNew1.r &&
+ colorRef1.g == colorNew1.g &&
+ colorRef1.b == colorNew1.b &&
+ colorRef2.r == colorNew2.r &&
+ colorRef2.g == colorNew2.g &&
+ colorRef2.b == colorNew2.b)
+ return true;
DeleteTexture(texName);
@@ -2275,7 +2308,8 @@ bool CEngine::ChangeTextureColor(const std::string& texName,
{
for (int x = sx; x < ex; x++)
{
- if (exclude != nullptr && IsExcludeColor(exclude, x,y) ) continue;
+ if (exclude != nullptr && IsExcludeColor(exclude, x,y) )
+ continue;
Color color = img.GetPixel(Math::IntPoint(x, y));
@@ -2905,7 +2939,8 @@ void CEngine::ApplyChange()
viewport, and renders the scene. */
void CEngine::Render()
{
- if (! m_render) return;
+ if (! m_render)
+ return;
m_statisticTriangle = 0;
m_lastState = -1;
@@ -2928,7 +2963,9 @@ void CEngine::Render()
if (m_drawWorld)
Draw3DScene();
+ m_app->StartPerformanceCounter(PCNT_RENDER_INTERFACE);
DrawInterface();
+ m_app->StopPerformanceCounter(PCNT_RENDER_INTERFACE);
// End the scene
m_device->EndScene();
@@ -2959,41 +2996,49 @@ void CEngine::Draw3DScene()
if (m_waterMode) m_water->DrawBack(); // draws water background
+ m_app->StartPerformanceCounter(PCNT_RENDER_TERRAIN);
+
+ // Draw terrain with shadows, if shadows enabled
if (m_shadowVisible)
{
m_lightMan->UpdateDeviceLights(ENG_OBJTYPE_TERRAIN);
- // Draw the terrain
-
- for (int l1 = 0; l1 < static_cast<int>( m_objectTree.size() ); l1++)
+ for (int objRank = 0; objRank < static_cast<int>(m_objects.size()); objRank++)
{
- EngineObjLevel1& p1 = m_objectTree[l1];
- if (! p1.used) continue;
+ if (! m_objects[objRank].used)
+ continue;
- // Should be loaded by now
- SetTexture(p1.tex1, 0);
- SetTexture(p1.tex2, 1);
+ if (m_objects[objRank].type != ENG_OBJTYPE_TERRAIN)
+ continue;
- for (int l2 = 0; l2 < static_cast<int>( p1.next.size() ); l2++)
- {
- EngineObjLevel2& p2 = p1.next[l2];
- if (! p2.used) continue;
+ if (! m_objects[objRank].drawWorld)
+ continue;
- int objRank = p2.objRank;
- if (m_objects[objRank].type != ENG_OBJTYPE_TERRAIN)
- continue;
- if (! m_objects[objRank].drawWorld)
- continue;
+ m_device->SetTransform(TRANSFORM_WORLD, m_objects[objRank].transform);
- m_device->SetTransform(TRANSFORM_WORLD, m_objects[objRank].transform);
+ if (! IsVisible(objRank))
+ continue;
- if (! IsVisible(objRank))
- continue;
+ int baseObjRank = m_objects[objRank].baseObjRank;
+ if (baseObjRank == -1)
+ continue;
+
+ assert(baseObjRank >= 0 && baseObjRank < static_cast<int>( m_baseObjects.size() ));
+
+ EngineBaseObject& p1 = m_baseObjects[baseObjRank];
+ if (! p1.used)
+ continue;
+
+ for (int l2 = 0; l2 < static_cast<int>( p1.next.size() ); l2++)
+ {
+ EngineBaseObjTexTier& p2 = p1.next[l2];
+
+ SetTexture(p2.tex1, 0);
+ SetTexture(p2.tex2, 1);
for (int l3 = 0; l3 < static_cast<int>( p2.next.size() ); l3++)
{
- EngineObjLevel3& p3 = p2.next[l3];
- if (! p3.used) continue;
+ EngineBaseObjLODTier& p3 = p2.next[l3];
if ( m_objects[objRank].distance < p3.min ||
m_objects[objRank].distance >= p3.max )
@@ -3001,26 +3046,12 @@ void CEngine::Draw3DScene()
for (int l4 = 0; l4 < static_cast<int>( p3.next.size() ); l4++)
{
- EngineObjLevel4& p4 = p3.next[l4];
- if (! p4.used) continue;
+ EngineBaseObjDataTier& p4 = p3.next[l4];
SetMaterial(p4.material);
SetState(p4.state);
- if (p4.type == ENG_TRIANGLE_TYPE_TRIANGLES)
- {
- m_device->DrawPrimitive( PRIMITIVE_TRIANGLES,
- &p4.vertices[0],
- p4.vertices.size() );
- m_statisticTriangle += p4.vertices.size() / 3;
- }
- if (p4.type == ENG_TRIANGLE_TYPE_SURFACE)
- {
- m_device->DrawPrimitive( PRIMITIVE_TRIANGLE_STRIP,
- &p4.vertices[0],
- p4.vertices.size() );
- m_statisticTriangle += p4.vertices.size() - 2;
- }
+ DrawObject(p4);
}
}
}
@@ -3030,51 +3061,60 @@ void CEngine::Draw3DScene()
DrawShadow();
}
- // Draw objects (non-terrain)
+ m_app->StopPerformanceCounter(PCNT_RENDER_TERRAIN);
+
+ // Draw other objects (and if shadows disabled, also terrain)
+
+ m_app->StartPerformanceCounter(PCNT_RENDER_OBJECTS);
bool transparent = false;
- for (int l1 = 0; l1 < static_cast<int>( m_objectTree.size() ); l1++)
+ for (int objRank = 0; objRank < static_cast<int>(m_objects.size()); objRank++)
{
- EngineObjLevel1& p1 = m_objectTree[l1];
- if (! p1.used) continue;
+ if (! m_objects[objRank].used)
+ continue;
- // Should be loaded by now
- SetTexture(p1.tex1, 0);
- SetTexture(p1.tex2, 1);
+ if (m_objects[objRank].type == ENG_OBJTYPE_TERRAIN)
+ continue;
- for (int l2 = 0; l2 < static_cast<int>( p1.next.size() ); l2++)
- {
- EngineObjLevel2& p2 = p1.next[l2];
- if (! p2.used) continue;
+ if (! m_objects[objRank].drawWorld)
+ continue;
- int objRank = p2.objRank;
+ m_device->SetTransform(TRANSFORM_WORLD, m_objects[objRank].transform);
- if (m_shadowVisible && m_objects[objRank].type == ENG_OBJTYPE_TERRAIN)
- continue;
+ if (! IsVisible(objRank))
+ continue;
- if (! m_objects[objRank].drawWorld)
- continue;
+ int baseObjRank = m_objects[objRank].baseObjRank;
+ if (baseObjRank == -1)
+ continue;
- m_device->SetTransform(TRANSFORM_WORLD, m_objects[objRank].transform);
+ assert(baseObjRank >= 0 && baseObjRank < static_cast<int>( m_baseObjects.size() ));
- if (! IsVisible(objRank))
- continue;
+ EngineBaseObject& p1 = m_baseObjects[baseObjRank];
+ if (! p1.used)
+ continue;
- m_lightMan->UpdateDeviceLights(m_objects[objRank].type);
+ m_lightMan->UpdateDeviceLights(m_objects[objRank].type);
+
+ for (int l2 = 0; l2 < static_cast<int>( p1.next.size() ); l2++)
+ {
+ EngineBaseObjTexTier& p2 = p1.next[l2];
+
+ SetTexture(p2.tex1, 0);
+ SetTexture(p2.tex2, 1);
for (int l3 = 0; l3 < static_cast<int>( p2.next.size() ); l3++)
{
- EngineObjLevel3& p3 = p2.next[l3];
- if (! p3.used) continue;
+ EngineBaseObjLODTier& p3 = p2.next[l3];
if ( m_objects[objRank].distance < p3.min ||
- m_objects[objRank].distance >= p3.max ) continue;
+ m_objects[objRank].distance >= p3.max )
+ continue;
for (int l4 = 0; l4 < static_cast<int>( p3.next.size() ); l4++)
{
- EngineObjLevel4& p4 = p3.next[l4];
- if (! p4.used) continue;
+ EngineBaseObjDataTier& p4 = p3.next[l4];
if (m_objects[objRank].transparency != 0.0f) // transparent ?
{
@@ -3085,22 +3125,7 @@ void CEngine::Draw3DScene()
SetMaterial(p4.material);
SetState(p4.state);
- if (p4.type == ENG_TRIANGLE_TYPE_TRIANGLES)
- {
- m_device->DrawPrimitive( PRIMITIVE_TRIANGLES,
- &p4.vertices[0],
- p4.vertices.size() );
-
- m_statisticTriangle += p4.vertices.size() / 3;
- }
- else if (p4.type == ENG_TRIANGLE_TYPE_SURFACE)
- {
- m_device->DrawPrimitive( PRIMITIVE_TRIANGLE_STRIP,
- &p4.vertices[0],
- p4.vertices.size() );
-
- m_statisticTriangle += p4.vertices.size() - 2;
- }
+ DrawObject(p4);
}
}
}
@@ -3113,47 +3138,52 @@ void CEngine::Draw3DScene()
int tState = ENG_RSTATE_TTEXTURE_BLACK | ENG_RSTATE_2FACE;
Color tColor = Color(68.0f / 255.0f, 68.0f / 255.0f, 68.0f / 255.0f, 68.0f / 255.0f);
- for (int l1 = 0; l1 < static_cast<int>( m_objectTree.size() ); l1++)
+ for (int objRank = 0; objRank < static_cast<int>(m_objects.size()); objRank++)
{
- EngineObjLevel1& p1 = m_objectTree[l1];
- if (! p1.used) continue;
+ if (! m_objects[objRank].used)
+ continue;
- // Should be loaded by now
- SetTexture(p1.tex1, 0);
- SetTexture(p1.tex2, 1);
+ if (m_objects[objRank].type == ENG_OBJTYPE_TERRAIN)
+ continue;
- for (int l2 = 0; l2 < static_cast<int>( p1.next.size() ); l2++)
- {
- EngineObjLevel2& p2 = p1.next[l2];
- if (! p2.used) continue;
+ if (! m_objects[objRank].drawWorld)
+ continue;
- int objRank = p2.objRank;
+ m_device->SetTransform(TRANSFORM_WORLD, m_objects[objRank].transform);
- if (m_shadowVisible && m_objects[objRank].type == ENG_OBJTYPE_TERRAIN)
- continue;
+ if (! IsVisible(objRank))
+ continue;
- if (! m_objects[objRank].drawWorld)
- continue;
+ int baseObjRank = m_objects[objRank].baseObjRank;
+ if (baseObjRank == -1)
+ continue;
- m_device->SetTransform(TRANSFORM_WORLD, m_objects[objRank].transform);
+ assert(baseObjRank >= 0 && baseObjRank < static_cast<int>( m_baseObjects.size() ));
- if (! IsVisible(objRank))
- continue;
+ EngineBaseObject& p1 = m_baseObjects[baseObjRank];
+ if (! p1.used)
+ continue;
+
+ m_lightMan->UpdateDeviceLights(m_objects[objRank].type);
+
+ for (int l2 = 0; l2 < static_cast<int>( p1.next.size() ); l2++)
+ {
+ EngineBaseObjTexTier& p2 = p1.next[l2];
- m_lightMan->UpdateDeviceLights(m_objects[objRank].type);
+ SetTexture(p2.tex1, 0);
+ SetTexture(p2.tex2, 1);
for (int l3 = 0; l3 < static_cast<int>( p2.next.size() ); l3++)
{
- EngineObjLevel3& p3 = p2.next[l3];
- if (! p3.used) continue;
+ EngineBaseObjLODTier& p3 = p2.next[l3];
- if ( m_objects[objRank].distance < p3.min ||
- m_objects[objRank].distance >= p3.max ) continue;
+ if (m_objects[objRank].distance < p3.min ||
+ m_objects[objRank].distance >= p3.max)
+ continue;
for (int l4 = 0; l4 < static_cast<int>( p3.next.size() ); l4++)
{
- EngineObjLevel4& p4 = p3.next[l4];
- if (! p4.used) continue;
+ EngineBaseObjDataTier& p4 = p3.next[l4];
if (m_objects[objRank].transparency == 0.0f)
continue;
@@ -3161,40 +3191,61 @@ void CEngine::Draw3DScene()
SetMaterial(p4.material);
SetState(tState, tColor);
- if (p4.type == ENG_TRIANGLE_TYPE_TRIANGLES)
- {
- m_device->DrawPrimitive( PRIMITIVE_TRIANGLES,
- &p4.vertices[0],
- p4.vertices.size() );
-
- m_statisticTriangle += p4.vertices.size() / 3;
- }
- else if (p4.type == ENG_TRIANGLE_TYPE_SURFACE)
- {
- m_device->DrawPrimitive( PRIMITIVE_TRIANGLE_STRIP,
- &p4.vertices[0],
- p4.vertices.size() );
- m_statisticTriangle += p4.vertices.size() - 2;
- }
+ DrawObject(p4);
}
}
}
}
}
+ m_app->StopPerformanceCounter(PCNT_RENDER_OBJECTS);
+
m_lightMan->UpdateDeviceLights(ENG_OBJTYPE_TERRAIN);
- if (m_waterMode) m_water->DrawSurf(); // draws water surface
+ if (m_waterMode)
+ {
+ m_app->StartPerformanceCounter(PCNT_RENDER_WATER);
+ m_water->DrawSurf(); // draws water surface
+ m_app->StopPerformanceCounter(PCNT_RENDER_WATER);
+ }
+ m_app->StartPerformanceCounter(PCNT_RENDER_PARTICLE);
m_particle->DrawParticle(SH_WORLD); // draws the particles of the 3D world
+ m_app->StopPerformanceCounter(PCNT_RENDER_PARTICLE);
+
m_lightning->Draw(); // draws lightning
- // TODO: fix white screen error; commenting out temporarily
- // if (m_lensMode) DrawForegroundImage(); // draws the foreground
+ if (m_lensMode) DrawForegroundImage(); // draws the foreground
if (! m_overFront) DrawOverColor(); // draws the foreground color
}
+void CEngine::DrawObject(const EngineBaseObjDataTier& p4)
+{
+ if (p4.staticBufferId != 0)
+ {
+ m_device->DrawStaticBuffer(p4.staticBufferId);
+
+ if (p4.type == ENG_TRIANGLE_TYPE_TRIANGLES)
+ m_statisticTriangle += p4.vertices.size() / 3;
+ else
+ m_statisticTriangle += p4.vertices.size() - 2;
+ }
+ else
+ {
+ if (p4.type == ENG_TRIANGLE_TYPE_TRIANGLES)
+ {
+ m_device->DrawPrimitive(PRIMITIVE_TRIANGLES, &p4.vertices[0], p4.vertices.size());
+ m_statisticTriangle += p4.vertices.size() / 3;
+ }
+ else
+ {
+ m_device->DrawPrimitive(PRIMITIVE_TRIANGLE_STRIP, &p4.vertices[0], p4.vertices.size() );
+ m_statisticTriangle += p4.vertices.size() - 2;
+ }
+ }
+}
+
void CEngine::DrawInterface()
{
m_device->SetRenderState(RENDER_STATE_DEPTH_TEST, false);
@@ -3240,66 +3291,57 @@ void CEngine::DrawInterface()
m_device->SetTransform(TRANSFORM_VIEW, m_matView);
- for (int l1 = 0; l1 < static_cast<int>( m_objectTree.size() ); l1++)
+ for (int objRank = 0; objRank < static_cast<int>(m_objects.size()); objRank++)
{
- EngineObjLevel1& p1 = m_objectTree[l1];
- if (! p1.used) continue;
+ if (! m_objects[objRank].used)
+ continue;
- // Should be loaded by now
- SetTexture(p1.tex1, 0);
- SetTexture(p1.tex2, 1);
+ if (m_shadowVisible && m_objects[objRank].type == ENG_OBJTYPE_TERRAIN)
+ continue;
- for (int l2 = 0; l2 < static_cast<int>( p1.next.size() ); l2++)
- {
- EngineObjLevel2& p2 = p1.next[l2];
- if (! p2.used) continue;
+ if (! m_objects[objRank].drawFront)
+ continue;
- int objRank = p2.objRank;
+ m_device->SetTransform(TRANSFORM_WORLD, m_objects[objRank].transform);
- if (m_shadowVisible && m_objects[objRank].type == ENG_OBJTYPE_TERRAIN)
- continue;
+ if (! IsVisible(objRank))
+ continue;
- if (! m_objects[objRank].drawFront)
- continue;
+ int baseObjRank = m_objects[objRank].baseObjRank;
+ if (baseObjRank == -1)
+ continue;
- m_device->SetTransform(TRANSFORM_WORLD, m_objects[objRank].transform);
+ assert(baseObjRank >= 0 && baseObjRank < static_cast<int>( m_baseObjects.size() ));
- if (! IsVisible(objRank))
- continue;
+ EngineBaseObject& p1 = m_baseObjects[baseObjRank];
+ if (! p1.used)
+ continue;
- m_lightMan->UpdateDeviceLights(m_objects[objRank].type);
+ m_lightMan->UpdateDeviceLights(m_objects[objRank].type);
+
+ for (int l2 = 0; l2 < static_cast<int>( p1.next.size() ); l2++)
+ {
+ EngineBaseObjTexTier& p2 = p1.next[l2];
+
+ SetTexture(p2.tex1, 0);
+ SetTexture(p2.tex2, 1);
for (int l3 = 0; l3 < static_cast<int>( p2.next.size() ); l3++)
{
- EngineObjLevel3& p3 = p2.next[l3];
- if (! p3.used) continue;
+ EngineBaseObjLODTier& p3 = p2.next[l3];
- if ( m_objects[objRank].distance < p3.min ||
- m_objects[objRank].distance >= p3.max ) continue;
+ if (m_objects[objRank].distance < p3.min ||
+ m_objects[objRank].distance >= p3.max)
+ continue;
for (int l4 = 0; l4 < static_cast<int>( p3.next.size() ); l4++)
{
- EngineObjLevel4& p4 = p3.next[l4];
- if (! p4.used) continue;
+ EngineBaseObjDataTier& p4 = p3.next[l4];
SetMaterial(p4.material);
SetState(p4.state);
- if (p4.type == ENG_TRIANGLE_TYPE_TRIANGLES)
- {
- m_device->DrawPrimitive( PRIMITIVE_TRIANGLES,
- &p4.vertices[0],
- p4.vertices.size() );
-
- m_statisticTriangle += p4.vertices.size() / 3;
- }
- else if (p4.type == ENG_TRIANGLE_TYPE_SURFACE)
- {
- m_device->DrawPrimitive( PRIMITIVE_TRIANGLE_STRIP,
- &p4.vertices[0],
- p4.vertices.size() );
- m_statisticTriangle += p4.vertices.size() - 2;
- }
+ DrawObject(p4);
}
}
}
@@ -3328,8 +3370,270 @@ void CEngine::DrawInterface()
void CEngine::UpdateGroundSpotTextures()
{
- // TODO the original code modifying the textures is very complex, so stub for now
- GetLogger()->Trace("CEngine::UpdateGroundSpotTextures(): stub!\n");
+ if (!m_firstGroundSpot &&
+ m_groundMark.drawPos.x == m_groundMark.pos.x &&
+ m_groundMark.drawPos.z == m_groundMark.pos.z &&
+ m_groundMark.drawRadius == m_groundMark.radius &&
+ m_groundMark.drawIntensity == m_groundMark.intensity)
+ return;
+
+ for (int s = 0; s < 16; s++)
+ {
+ Math::Point min, max;
+ min.x = (s%4) * 254.0f - 1.0f; // 1 pixel cover
+ min.y = (s/4) * 254.0f - 1.0f;
+ max.x = min.x + 254.0f + 2.0f;
+ max.y = min.y + 254.0f + 2.0f;
+
+ bool clear = false;
+ bool set = false;
+
+ // Calculate the area to be erased.
+ int dot = static_cast<int>(m_groundMark.drawRadius/2.0f);
+
+ float tu, tv;
+ float cx, cy;
+
+ tu = (m_groundMark.drawPos.x+1600.0f)/3200.0f;
+ tv = (m_groundMark.drawPos.z+1600.0f)/3200.0f; // 0..1
+
+ cx = (tu*254.0f*4.0f)-0.5f;
+ cy = (tv*254.0f*4.0f)-0.5f;
+
+ if (dot == 0)
+ {
+ cx += 0.5f;
+ cy += 0.5f;
+ }
+
+ float px = cx-Math::Mod(cx, 1.0f);
+ float py = cy-Math::Mod(cy, 1.0f); // multiple of 1
+
+ if (m_firstGroundSpot ||
+ (m_groundMark.drawRadius != 0.0f &&
+ px+dot >= min.x && py+dot >= min.y &&
+ px-dot <= max.x && py-dot <= max.y))
+ {
+ clear = true;
+ }
+
+ // Calculate the area to draw.
+ dot = static_cast<int>(m_groundMark.radius/2.0f);
+
+ tu = (m_groundMark.pos.x+1600.0f)/3200.0f;
+ tv = (m_groundMark.pos.z+1600.0f)/3200.0f; // 0..1
+
+ cx = (tu*254.0f*4.0f)-0.5f;
+ cy = (tv*254.0f*4.0f)-0.5f;
+
+ if ( dot == 0 )
+ {
+ cx += 0.5f;
+ cy += 0.5f;
+ }
+
+ px = cx - Math::Mod(cx, 1.0f);
+ py = cy - Math::Mod(cy, 1.0f); // multiple of 1
+
+ if (m_groundMark.draw &&
+ px+dot >= min.x && py+dot >= min.y &&
+ px-dot <= max.x && py-dot <= max.y)
+ {
+ set = true;
+ }
+
+ if (clear || set)
+ {
+ CImage shadowImg(Math::IntPoint(256, 256));
+ shadowImg.Fill(Gfx::IntColor(255, 255, 255, 255));
+
+ // Draw the new shadows.
+ for (int i = 0; i < static_cast<int>( m_groundSpots.size() ); i++)
+ {
+ if (m_groundSpots[i].used == false ||
+ m_groundSpots[i].radius == 0.0f)
+ continue;
+
+ if (m_groundSpots[i].min == 0.0f &&
+ m_groundSpots[i].max == 0.0f)
+ {
+ dot = static_cast<int>(m_groundSpots[i].radius/2.0f);
+
+ tu = (m_groundSpots[i].pos.x+1600.0f)/3200.0f;
+ tv = (m_groundSpots[i].pos.z+1600.0f)/3200.0f; // 0..1
+
+ cx = (tu*254.0f*4.0f) - 0.5f;
+ cy = (tv*254.0f*4.0f) - 0.5f;
+
+ if (dot == 0)
+ {
+ cx += 0.5f;
+ cy += 0.5f;
+ }
+
+ px = cx-Math::Mod(cx, 1.0f);
+ py = cy-Math::Mod(cy, 1.0f); // multiple of 1
+
+ if (px+dot < min.x || py+dot < min.y ||
+ px-dot > max.x || py-dot > max.y)
+ continue;
+
+ for (int iy = -dot; iy <= dot; iy++)
+ {
+ for (int ix =- dot; ix <= dot; ix++)
+ {
+ float ppx = px+ix;
+ float ppy = py+iy;
+
+ if (ppx < min.x || ppy < min.y ||
+ ppx >= max.x || ppy >= max.y)
+ continue;
+
+ float intensity;
+ if (dot == 0)
+ intensity = 0.0f;
+ else
+ intensity = Math::Point(ppx-cx, ppy-cy).Length()/dot;
+
+ Gfx::Color color;
+ color.r = Math::Norm(m_groundSpots[i].color.r+intensity);
+ color.g = Math::Norm(m_groundSpots[i].color.g+intensity);
+ color.b = Math::Norm(m_groundSpots[i].color.b+intensity);
+
+ ppx -= min.x; // on the texture
+ ppy -= min.y;
+
+ shadowImg.SetPixel(Math::IntPoint(ppx, ppy), color);
+ }
+ }
+ }
+ else
+ {
+ for (int iy = 0; iy < 256; iy++)
+ {
+ for (int ix = 0; ix < 256; ix++)
+ {
+ Math::Vector pos;
+ pos.x = (256.0f * (s%4) + ix) * 3200.0f/1024.0f - 1600.0f;
+ pos.z = (256.0f * (s/4) + iy) * 3200.0f/1024.0f - 1600.0f;
+ pos.y = 0.0f;
+
+ float level = m_terrain->GetFloorLevel(pos, true);
+ if (level < m_groundSpots[i].min ||
+ level > m_groundSpots[i].max)
+ continue;
+
+ float intensity;
+ if (level > (m_groundSpots[i].max+m_groundSpots[i].min)/2.0f)
+ intensity = 1.0f - (m_groundSpots[i].max-level) / m_groundSpots[i].smooth;
+ else
+ intensity = 1.0f - (level-m_groundSpots[i].min) / m_groundSpots[i].smooth;
+
+ if (intensity < 0.0f) intensity = 0.0f;
+
+ Gfx::Color color;
+ color.r = Math::Norm(m_groundSpots[i].color.r+intensity);
+ color.g = Math::Norm(m_groundSpots[i].color.g+intensity);
+ color.b = Math::Norm(m_groundSpots[i].color.b+intensity);
+
+ shadowImg.SetPixel(Math::IntPoint(ix, iy), color);
+ }
+ }
+ }
+ }
+
+ if (set)
+ {
+ dot = static_cast<int>(m_groundMark.radius/2.0f);
+
+ tu = (m_groundMark.pos.x + 1600.0f) / 3200.0f;
+ tv = (m_groundMark.pos.z + 1600.0f) / 3200.0f; // 0..1
+
+ cx = (tu*254.0f*4.0f)-0.5f;
+ cy = (tv*254.0f*4.0f)-0.5f;
+
+ if (dot == 0)
+ {
+ cx += 0.5f;
+ cy += 0.5f;
+ }
+
+ px = cx-Math::Mod(cx, 1.0f);
+ py = cy-Math::Mod(cy, 1.0f); // multiple of 1
+
+ for (int iy = -dot; iy <= dot; iy++)
+ {
+ for (int ix = -dot; ix <= dot; ix++)
+ {
+ float ppx = px+ix;
+ float ppy = py+iy;
+
+ if (ppx < min.x || ppy < min.y ||
+ ppx >= max.x || ppy >= max.y)
+ continue;
+
+ ppx -= min.x; // on the texture
+ ppy -= min.y;
+
+ float intensity = 1.0f - Math::Point(ix, iy).Length() / dot;
+ if (intensity <= 0.0f)
+ continue;
+
+ intensity *= m_groundMark.intensity;
+
+ int j = (ix+dot) + (iy+dot) * m_groundMark.dx;
+ if (m_groundMark.table[j] == 1) // green ?
+ {
+ Gfx::Color color;
+ color.r = Math::Norm(1.0f-intensity);
+ color.g = 1.0f;
+ color.b = Math::Norm(1.0f-intensity);
+ shadowImg.SetPixel(Math::IntPoint(ppx, ppy), color);
+ }
+ if (m_groundMark.table[j] == 2) // red ?
+ {
+ Gfx::Color color;
+ color.r = 1.0f;
+ color.g = Math::Norm(1.0f-intensity);
+ color.b = Math::Norm(1.0f-intensity);
+ shadowImg.SetPixel(Math::IntPoint(ppx, ppy), color);
+ }
+ }
+ }
+ }
+
+ std::stringstream str;
+ str << "shadow" << std::setfill('0') << std::setw(2) << s << ".png";
+ std::string texName = str.str();
+
+ DeleteTexture(texName);
+
+ Gfx::Texture tex = m_device->CreateTexture(&shadowImg, m_defaultTexParams);
+
+ m_texNameMap[texName] = tex;
+ m_revTexNameMap[tex] = texName;
+ }
+ }
+
+ for (int i = 0; i < static_cast<int>( m_groundSpots.size() ); i++)
+ {
+ if (m_groundSpots[i].used == false ||
+ m_groundSpots[i].radius == 0.0f)
+ {
+ m_groundSpots[i].drawRadius = 0.0f;
+ }
+ else
+ {
+ m_groundSpots[i].drawPos = m_groundSpots[i].pos;
+ m_groundSpots[i].drawRadius = m_groundSpots[i].radius;
+ }
+ }
+
+ m_groundMark.drawPos = m_groundMark.pos;
+ m_groundMark.drawRadius = m_groundMark.radius;
+ m_groundMark.drawIntensity = m_groundMark.intensity;
+
+ m_firstGroundSpot = false;
}
void CEngine::DrawShadow()
@@ -3366,11 +3670,13 @@ void CEngine::DrawShadow()
float lastIntensity = -1.0f;
for (int i = 0; i < static_cast<int>( m_shadows.size() ); i++)
{
- if (m_shadows[i].hide) continue;
+ if (m_shadows[i].hide)
+ continue;
Math::Vector pos = m_shadows[i].pos; // pos = center of the shadow on the ground
- if (m_eyePt.y == pos.y) continue; // camera at the same level?
+ if (m_eyePt.y == pos.y)
+ continue; // camera at the same level?
float d = 0.0f;
float D = 0.0f;
@@ -3386,7 +3692,9 @@ void CEngine::DrawShadow()
if ( h > 4.0f ) h = 4.0f;
D = Math::Distance(m_eyePt, pos);
- if ( D >= endDeepView ) continue;
+ if (D >= endDeepView)
+ continue;
+
d = D*h/height;
pos.x += (m_eyePt.x-pos.x)*d/D;
@@ -3402,7 +3710,9 @@ void CEngine::DrawShadow()
if ( h > 4.0f ) h = 4.0f;
D = Math::Distance(m_eyePt, pos);
- if ( D >= endDeepView ) continue;
+ if (D >= endDeepView)
+ continue;
+
d = D*h/height;
pos.x += (m_eyePt.x-pos.x)*d/D;
@@ -3510,7 +3820,8 @@ void CEngine::DrawShadow()
if ( D > startDeepView )
intensity *= 1.0f-(D-startDeepView)/(endDeepView-startDeepView);
- if (intensity == 0.0f) continue;
+ if (intensity == 0.0f)
+ continue;
if (lastIntensity != intensity) // intensity changed?
{
@@ -3526,7 +3837,6 @@ void CEngine::DrawShadow()
m_device->SetRenderState(RENDER_STATE_LIGHTING, true);
}
-// STATUS: TESTED, VERIFIED
void CEngine::DrawBackground()
{
if (m_skyMode && m_cloud->GetLevel() != 0.0f) // clouds ?
@@ -3546,7 +3856,6 @@ void CEngine::DrawBackground()
}
}
-// STATUS: TESTED
void CEngine::DrawBackgroundGradient(const Color& up, const Color& down)
{
Math::Point p1(0.0f, 0.5f);
@@ -3577,7 +3886,6 @@ void CEngine::DrawBackgroundGradient(const Color& up, const Color& down)
AddStatisticTriangle(2);
}
-// Status: TESTED, VERIFIED
void CEngine::DrawBackgroundImage()
{
Math::Point p1, p2;
@@ -3586,7 +3894,7 @@ void CEngine::DrawBackgroundImage()
p2.x = 1.0f;
p2.y = 1.0f;
-Math::Vector n = Math::Vector(0.0f, 0.0f, -1.0f); // normal
+ Math::Vector n = Math::Vector(0.0f, 0.0f, -1.0f); // normal
float u1, u2, v1, v2;
if (m_backgroundFull)
@@ -3635,7 +3943,8 @@ Math::Vector n = Math::Vector(0.0f, 0.0f, -1.0f); // normal
void CEngine::DrawPlanet()
{
- if (! m_planet->PlanetExist()) return;
+ if (! m_planet->PlanetExist())
+ return;
m_device->SetRenderState(RENDER_STATE_DEPTH_WRITE, false);
m_device->SetRenderState(RENDER_STATE_LIGHTING, false);
@@ -3648,10 +3957,10 @@ void CEngine::DrawPlanet()
m_planet->Draw(); // draws the planets
}
-// Status: PART_TESTED
void CEngine::DrawForegroundImage()
{
- if (m_foregroundName.empty()) return;
+ if (m_foregroundName.empty())
+ return;
Math::Vector n = Math::Vector(0.0f, 0.0f, -1.0f); // normal
@@ -3684,12 +3993,11 @@ void CEngine::DrawForegroundImage()
AddStatisticTriangle(2);
}
-// Status: PART_TESTED
void CEngine::DrawOverColor()
{
- // TODO: fuzzy compare?
- if ( (m_overColor == Color(0.0f, 0.0f, 0.0f, 0.0f) && m_overMode == ENG_RSTATE_TCOLOR_BLACK) ||
- (m_overColor == Color(1.0f, 1.0f, 1.0f, 1.0f) && m_overMode == ENG_RSTATE_TCOLOR_WHITE) ) return;
+ if ((m_overColor == Color(0.0f, 0.0f, 0.0f, 0.0f) && m_overMode == ENG_RSTATE_TCOLOR_BLACK) ||
+ (m_overColor == Color(1.0f, 1.0f, 1.0f, 1.0f) && m_overMode == ENG_RSTATE_TCOLOR_WHITE))
+ return;
Math::Point p1(0.0f, 0.0f);
Math::Point p2(1.0f, 1.0f);
@@ -3703,11 +4011,6 @@ void CEngine::DrawOverColor()
SetState(m_overMode);
- // TODO: set also with m_overMode ?
- m_device->SetRenderState(RENDER_STATE_DEPTH_WRITE, false);
- m_device->SetRenderState(RENDER_STATE_LIGHTING, false);
- m_device->SetRenderState(RENDER_STATE_FOG, false);
-
m_device->SetTransform(TRANSFORM_VIEW, m_matViewInterface);
m_device->SetTransform(TRANSFORM_PROJECTION, m_matProjInterface);
m_device->SetTransform(TRANSFORM_WORLD, m_matWorldInterface);
@@ -3724,7 +4027,6 @@ void CEngine::DrawOverColor()
AddStatisticTriangle(2);
}
-// Status: TESTED, VERIFIED
void CEngine::DrawHighlight()
{
Math::Point min, max;
@@ -3816,7 +4118,6 @@ void CEngine::DrawHighlight()
m_device->DrawPrimitive(PRIMITIVE_LINE_STRIP, line, 3);
}
-// Status: TESTED, VERIFIED
void CEngine::DrawMouse()
{
MouseMode mode = m_app->GetMouseMode();
@@ -3850,7 +4151,6 @@ void CEngine::DrawMouse()
DrawMouseSprite(pos, m_mouseSize, m_mice[index].icon2);
}
-// Status: TESTED, VERIFIED
void CEngine::DrawMouseSprite(Math::Point pos, Math::Point size, int icon)
{
if (icon == -1)
@@ -3889,15 +4189,10 @@ void CEngine::DrawStats()
if (!m_showStats)
return;
- std::stringstream str;
- str << "Triangles: ";
- str << m_statisticTriangle;
- std::string triangleText = str.str();
-
float height = m_text->GetAscent(FONT_COLOBOT, 12.0f);
float width = 0.2f;
- Math::Point pos(0.04f, 0.04f + height);
+ Math::Point pos(0.04f, 0.04f + 17 * height);
SetState(ENG_RSTATE_OPAQUE_COLOR);
@@ -3905,9 +4200,9 @@ void CEngine::DrawStats()
VertexCol vertex[4] =
{
- VertexCol(Math::Vector(pos.x , pos.y - height, 0.0f), black),
+ VertexCol(Math::Vector(pos.x , pos.y - 17 * height, 0.0f), black),
VertexCol(Math::Vector(pos.x , pos.y + height, 0.0f), black),
- VertexCol(Math::Vector(pos.x + width, pos.y - height, 0.0f), black),
+ VertexCol(Math::Vector(pos.x + width, pos.y - 17 * height, 0.0f), black),
VertexCol(Math::Vector(pos.x + width, pos.y + height, 0.0f), black)
};
@@ -3915,7 +4210,107 @@ void CEngine::DrawStats()
SetState(ENG_RSTATE_TEXT);
- m_text->DrawText(triangleText, FONT_COLOBOT, 12.0f, pos, 1.0f, TEXT_ALIGN_LEFT, 0, Color(1.0f, 1.0f, 1.0f, 1.0f));
+ std::stringstream str;
+
+ str.str("");
+ str << "Event processing: " << std::fixed << std::setprecision(2) << m_app->GetPerformanceCounterData(PCNT_EVENT_PROCESSING);
+ m_text->DrawText(str.str(), FONT_COLOBOT, 12.0f, pos, 1.0f, TEXT_ALIGN_LEFT, 0, Color(1.0f, 1.0f, 1.0f, 1.0f));
+
+ pos.y -= height;
+ pos.y -= height;
+
+
+ str.str("");
+ str << "Frame update: " << std::fixed << std::setprecision(2) << m_app->GetPerformanceCounterData(PCNT_UPDATE_ALL);
+ m_text->DrawText(str.str(), FONT_COLOBOT, 12.0f, pos, 1.0f, TEXT_ALIGN_LEFT, 0, Color(1.0f, 1.0f, 1.0f, 1.0f));
+
+ pos.y -= height;
+
+ str.str("");
+ str << "Engine update: " << std::fixed << std::setprecision(2) << m_app->GetPerformanceCounterData(PCNT_UPDATE_ENGINE);
+ m_text->DrawText(str.str(), FONT_COLOBOT, 12.0f, pos, 1.0f, TEXT_ALIGN_LEFT, 0, Color(1.0f, 1.0f, 1.0f, 1.0f));
+
+ pos.y -= height;
+
+ str.str("");
+ str << "Particle update: " << std::fixed << std::setprecision(2) << m_app->GetPerformanceCounterData(PCNT_UPDATE_PARTICLE);
+ m_text->DrawText(str.str(), FONT_COLOBOT, 12.0f, pos, 1.0f, TEXT_ALIGN_LEFT, 0, Color(1.0f, 1.0f, 1.0f, 1.0f));
+
+ pos.y -= height;
+
+ str.str("");
+ str << "Game update: " << std::fixed << std::setprecision(2) << m_app->GetPerformanceCounterData(PCNT_UPDATE_GAME);
+ m_text->DrawText(str.str(), FONT_COLOBOT, 12.0f, pos, 1.0f, TEXT_ALIGN_LEFT, 0, Color(1.0f, 1.0f, 1.0f, 1.0f));
+
+ pos.y -= height;
+
+ float otherUpdate = Math::Max(0.0f, m_app->GetPerformanceCounterData(PCNT_UPDATE_ALL) -
+ m_app->GetPerformanceCounterData(PCNT_UPDATE_ENGINE) -
+ m_app->GetPerformanceCounterData(PCNT_UPDATE_PARTICLE) -
+ m_app->GetPerformanceCounterData(PCNT_UPDATE_GAME));
+
+ str.str("");
+ str << "Other update: " << std::fixed << std::setprecision(2) << otherUpdate;
+ m_text->DrawText(str.str(), FONT_COLOBOT, 12.0f, pos, 1.0f, TEXT_ALIGN_LEFT, 0, Color(1.0f, 1.0f, 1.0f, 1.0f));
+
+ pos.y -= height;
+ pos.y -= height;
+
+
+ str.str("");
+ str << "Frame render: " << std::fixed << std::setprecision(2) << m_app->GetPerformanceCounterData(PCNT_RENDER_ALL);
+ m_text->DrawText(str.str(), FONT_COLOBOT, 12.0f, pos, 1.0f, TEXT_ALIGN_LEFT, 0, Color(1.0f, 1.0f, 1.0f, 1.0f));
+
+ pos.y -= height;
+
+ str.str("");
+ str << "Particle render: " << std::fixed << std::setprecision(2) << m_app->GetPerformanceCounterData(PCNT_RENDER_PARTICLE);
+ m_text->DrawText(str.str(), FONT_COLOBOT, 12.0f, pos, 1.0f, TEXT_ALIGN_LEFT, 0, Color(1.0f, 1.0f, 1.0f, 1.0f));
+
+ pos.y -= height;
+
+ str.str("");
+ str << "Water render: " << std::fixed << std::setprecision(2) << m_app->GetPerformanceCounterData(PCNT_RENDER_WATER);
+ m_text->DrawText(str.str(), FONT_COLOBOT, 12.0f, pos, 1.0f, TEXT_ALIGN_LEFT, 0, Color(1.0f, 1.0f, 1.0f, 1.0f));
+
+ pos.y -= height;
+
+ str.str("");
+ str << "Terrain render: " << std::fixed << std::setprecision(2) << m_app->GetPerformanceCounterData(PCNT_RENDER_TERRAIN);
+ m_text->DrawText(str.str(), FONT_COLOBOT, 12.0f, pos, 1.0f, TEXT_ALIGN_LEFT, 0, Color(1.0f, 1.0f, 1.0f, 1.0f));
+
+ pos.y -= height;
+
+ str.str("");
+ str << "Objects render: " << std::fixed << std::setprecision(2) << m_app->GetPerformanceCounterData(PCNT_RENDER_OBJECTS);
+ m_text->DrawText(str.str(), FONT_COLOBOT, 12.0f, pos, 1.0f, TEXT_ALIGN_LEFT, 0, Color(1.0f, 1.0f, 1.0f, 1.0f));
+
+ pos.y -= height;
+
+ str.str("");
+ str << "UI render: " << std::fixed << std::setprecision(2) << m_app->GetPerformanceCounterData(PCNT_RENDER_INTERFACE);
+ m_text->DrawText(str.str(), FONT_COLOBOT, 12.0f, pos, 1.0f, TEXT_ALIGN_LEFT, 0, Color(1.0f, 1.0f, 1.0f, 1.0f));
+
+ pos.y -= height;
+
+ float otherRender = m_app->GetPerformanceCounterData(PCNT_RENDER_ALL) -
+ m_app->GetPerformanceCounterData(PCNT_RENDER_PARTICLE) -
+ m_app->GetPerformanceCounterData(PCNT_RENDER_WATER) -
+ m_app->GetPerformanceCounterData(PCNT_RENDER_TERRAIN) -
+ m_app->GetPerformanceCounterData(PCNT_RENDER_OBJECTS) -
+ m_app->GetPerformanceCounterData(PCNT_RENDER_INTERFACE);
+
+ str.str("");
+ str << "Other render: " << std::fixed << std::setprecision(2) << otherRender;
+ m_text->DrawText(str.str(), FONT_COLOBOT, 12.0f, pos, 1.0f, TEXT_ALIGN_LEFT, 0, Color(1.0f, 1.0f, 1.0f, 1.0f));
+
+ pos.y -= height;
+ pos.y -= height;
+
+
+ str.str("");
+ str << "Triangles: " << m_statisticTriangle;
+ m_text->DrawText(str.str(), FONT_COLOBOT, 12.0f, pos, 1.0f, TEXT_ALIGN_LEFT, 0, Color(1.0f, 1.0f, 1.0f, 1.0f));
pos.y -= height;
diff --git a/src/graphics/engine/engine.h b/src/graphics/engine/engine.h
index 27f0173..c9391db 100644
--- a/src/graphics/engine/engine.h
+++ b/src/graphics/engine/engine.h
@@ -151,7 +151,7 @@ struct EngineTriangle
//! 2nd texture
std::string tex2Name;
- EngineTriangle()
+ inline EngineTriangle()
{
state = ENG_RSTATE_NORMAL;
}
@@ -178,6 +178,92 @@ enum EngineObjectType
ENG_OBJTYPE_METAL = 6
};
+
+/**
+ * \struct EngineBaseObjDataTier
+ * \brief Tier 4 of object tree (data)
+ */
+struct EngineBaseObjDataTier
+{
+ EngineTriangleType type;
+ Material material;
+ int state;
+ std::vector<VertexTex2> vertices;
+ unsigned int staticBufferId;
+ bool updateStaticBuffer;
+
+ inline EngineBaseObjDataTier(EngineTriangleType type = ENG_TRIANGLE_TYPE_TRIANGLES,
+ const Material& material = Material(),
+ int state = ENG_RSTATE_NORMAL)
+ : type(type), material(material), state(state), staticBufferId(0), updateStaticBuffer(false) {}
+};
+
+/**
+ * \struct EngineBaseObjLODTier
+ * \brief Tier 3 of base object tree (LOD)
+ */
+struct EngineBaseObjLODTier
+{
+ float min;
+ float max;
+ std::vector<EngineBaseObjDataTier> next;
+
+ inline EngineBaseObjLODTier(float min = 0.0f, float max = 0.0f)
+ : min(min), max(max) {}
+};
+
+/**
+ * \struct EngineBaseObjTexTier
+ * \brief Tier 2 of base object tree (textures)
+ */
+struct EngineBaseObjTexTier
+{
+ std::string tex1Name;
+ Texture tex1;
+ std::string tex2Name;
+ Texture tex2;
+ std::vector<EngineBaseObjLODTier> next;
+
+ inline EngineBaseObjTexTier(const std::string& tex1Name = "", const std::string& tex2Name = "")
+ : tex1Name(tex1Name), tex2Name(tex2Name) {}
+};
+
+/**
+ * \struct BaseEngineObject
+ * \brief Base (template) object - geometry for engine objects
+ *
+ * This is also the tier 1 of base object tree.
+ */
+struct EngineBaseObject
+{
+ //! If true, base object is valid in objects vector
+ bool used;
+ //! Number of triangles
+ int totalTriangles;
+ //! Bounding box min (origin 0,0,0 always included)
+ Math::Vector bboxMin;
+ //! bounding box max (origin 0,0,0 always included)
+ Math::Vector bboxMax;
+ //! Radius of the sphere at the origin
+ float radius;
+ //! Next tier (LOD)
+ std::vector<EngineBaseObjTexTier> next;
+
+ inline EngineBaseObject()
+ {
+ LoadDefault();
+ }
+
+ inline void LoadDefault()
+ {
+ used = false;
+ totalTriangles = 0;
+ bboxMax.LoadZero();
+ bboxMin.LoadZero();
+ radius = 0.0f;
+ }
+};
+
/**
* \struct EngineObject
* \brief Object drawn by the graphics engine
@@ -186,33 +272,27 @@ struct EngineObject
{
//! If true, object is valid in objects vector
bool used;
+ //! Rank of associated base engine object
+ int baseObjRank;
//! If true, the object is drawn
bool visible;
//! If true, object is behind the 2D interface
bool drawWorld;
//! If true, the shape is before the 2D interface
bool drawFront;
- //! Number of triangles
- int totalTriangles;
//! Type of object
- EngineObjectType type;
+ EngineObjectType type;
//! Transformation matrix
Math::Matrix transform;
//! Distance to object from eye point
float distance;
- //! Bounding box min (origin 0,0,0 always included)
- Math::Vector bboxMin;
- //! bounding box max (origin 0,0,0 always included)
- Math::Vector bboxMax;
- //! Radius of the sphere at the origin
- float radius;
//! Rank of the associated shadow
int shadowRank;
//! Transparency of the object [0, 1]
float transparency;
//! Calls LoadDefault()
- EngineObject()
+ inline EngineObject()
{
LoadDefault();
}
@@ -221,88 +301,18 @@ struct EngineObject
inline void LoadDefault()
{
used = false;
+ baseObjRank = -1;
visible = false;
drawWorld = false;
drawFront = false;
- totalTriangles = 0;
type = ENG_OBJTYPE_NULL;
transform.LoadIdentity();
- bboxMax.LoadZero();
- bboxMin.LoadZero();
distance = 0.0f;
- radius = 0.0f;
shadowRank = -1;
transparency = 0.0f;
}
};
-struct EngineObjLevel1;
-struct EngineObjLevel2;
-struct EngineObjLevel3;
-struct EngineObjLevel4;
-
-/**
- * \struct EngineObjLevel4
- * \brief Tier 4 of object tree
- */
-struct EngineObjLevel4
-{
- bool used;
- EngineTriangleType type;
- Material material;
- int state;
- std::vector<VertexTex2> vertices;
-
- EngineObjLevel4(bool used = false,
- EngineTriangleType type = ENG_TRIANGLE_TYPE_TRIANGLES,
- const Material& material = Material(),
- int state = ENG_RSTATE_NORMAL);
-};
-
-/**
- * \struct EngineObjLevel3
- * \brief Tier 3 of object tree
- */
-struct EngineObjLevel3
-{
- bool used;
- float min;
- float max;
- std::vector<EngineObjLevel4> next;
-
- EngineObjLevel3(bool used = false, float min = 0.0f, float max = 0.0f);
-};
-
-/**
- * \struct EngineObjLevel2
- * \brief Tier 2 of object tree
- */
-struct EngineObjLevel2
-{
- bool used;
- int objRank;
- std::vector<EngineObjLevel3> next;
-
- EngineObjLevel2(bool used = false, int objRank = -1);
-};
-
-/**
- * \struct EngineObjLevel1
- * \brief Tier 1 of object tree
- */
-struct EngineObjLevel1
-{
- bool used;
- std::string tex1Name;
- Texture tex1;
- std::string tex2Name;
- Texture tex2;
- std::vector<EngineObjLevel2> next;
-
- EngineObjLevel1(bool used = false, const std::string& tex1Name = "",
- const std::string& tex2Name = "");
-};
-
/**
* \struct EngineShadowType
* \brief Type of shadow drawn by the graphics engine
@@ -342,12 +352,12 @@ struct EngineShadow
//! Height from the ground
float height;
- EngineShadow()
+ inline EngineShadow()
{
LoadDefault();
}
- void LoadDefault()
+ inline void LoadDefault()
{
used = false;
hide = false;
@@ -384,12 +394,12 @@ struct EngineGroundSpot
//! Radius of the shadow drawn
float drawRadius;
- EngineGroundSpot()
+ inline EngineGroundSpot()
{
LoadDefault();
}
- void LoadDefault()
+ inline void LoadDefault()
{
used = false;
color = Color();
@@ -448,12 +458,12 @@ struct EngineGroundMark
//! Pointer to the table
char* table;
- EngineGroundMark()
+ inline EngineGroundMark()
{
LoadDefault();
}
- void LoadDefault()
+ inline void LoadDefault()
{
draw = false;
phase = ENG_GR_MARK_PHASE_NULL;
@@ -545,10 +555,10 @@ struct EngineMouse
//! Hot point
Math::Point hotPoint;
- EngineMouse(int icon1 = -1, int icon2 = -1, int iconShadow = -1,
- EngineRenderState mode1 = ENG_RSTATE_NORMAL,
- EngineRenderState mode2 = ENG_RSTATE_NORMAL,
- Math::Point hotPoint = Math::Point())
+ inline EngineMouse(int icon1 = -1, int icon2 = -1, int iconShadow = -1,
+ EngineRenderState mode1 = ENG_RSTATE_NORMAL,
+ EngineRenderState mode2 = ENG_RSTATE_NORMAL,
+ Math::Point hotPoint = Math::Point())
{
this->icon1 = icon1;
this->icon2 = icon2;
@@ -609,27 +619,36 @@ struct EngineMouse
*
* Objects are uniquely identified by object rank obtained at object creation. Creating an
* object equals to allocating space for EngineObject structure which holds object parameters.
- * Object's geometric data is stored in a separate structure - a 4-tier tree which splits
- * the information of each geometric triangle.
+ *
+ * Object's geometric data is stored as a separate object -- base engine object. Each object
+ * must reference a valid base engine object or an empty base engine object (with rank = -1).
+ * This many-to-one association allows to share same geometric data (e.g. from same model)
+ * across objects.
+ *
+ * Base engine object data is stored in a 4-tier tree which splits the data describing triangles.
*
* The 4 tiers contain the following information:
- * - level 1 (EngineObjLevel1) - two textures (names and structs) applied to triangles,
- * - level 2 (EngineObjLevel2) - object rank
- * - level 3 (EngineObjLevel3) - minumum and maximum LOD (=level of detail)
- * - level 4 (EngineObjLevel4) - type of object*, material, render state and the actual triangle data
+ * - level 1 (EngineBaseObject) - geometric statistics
+ * - level 2 (EngineBaseObjTexTier) - two textures (names and structs) applied to triangles,
+ * - level 3 (EngineBaseObjLODTier) - minumum and maximum LOD (=level of detail)
+ * - level 4 (EngineBaseObjDataTier) - type of object*, material, render state and the actual vertex data
*
- * NOTE: type of object in this context means only the internal type in 3D engine. It is not related
+ * *NOTE: type of object in this context means only the internal type in 3D engine. It is not related
* to CObject types.
*
+ * Last tier containing vertex data contains also an ID of static buffer holding the data.
+ * The static buffer is created and updated with new data as needed.
+ *
* Such tiered structure complicates loops over all object data, but saves a lot of memory and
- * optimizes the rendering process (for instance, switching of textures is an expensive operation).
+ * optimizes the rendering process.
*
* \section Shadows Shadows
*
* Each engine object can be associated with a shadow (EngineShadow). Like objects, shadows are
* identified by their rank obtained upon creation.
*
- * ...
+ * Shadows are drawn as circular spots on the ground, except for shadows for worms, which have
+ * special mode for them.
*
* \section RenderStates Render States
*
@@ -692,12 +711,6 @@ public:
//! Writes a screenshot containing the current frame
bool WriteScreenShot(const std::string& fileName, int width, int height);
-
- //! Reads settings from INI
- bool ReadSettings();
- //! Writes settings to INI
- bool WriteSettings();
-
//@{
//! Management of game pause mode
void SetPause(bool pause);
@@ -747,58 +760,73 @@ public:
/* *************** Object management *************** */
+ // Base objects
+
+ //! Creates a base object and returns its rank
+ int CreateBaseObject();
+ //! Deletes a base object
+ void DeleteBaseObject(int baseObjRank);
+ //! Deletes all base objects
+ void DeleteAllBaseObjects();
+
+ //! Copies geometry between two base objects
+ void CopyBaseObject(int sourceBaseObjRank, int destBaseObjRank);
+
+ //! Adds triangles to given object with the specified params
+ void AddBaseObjTriangles(int baseObjRank, const std::vector<VertexTex2>& vertices,
+ EngineTriangleType triangleType,
+ const Material& material, int state,
+ std::string tex1Name, std::string tex2Name,
+ float min, float max, bool globalUpdate);
+
+ //! Adds a tier 4 engine object directly
+ void AddBaseObjQuick(int baseObjRank, const EngineBaseObjDataTier& buffer,
+ std::string tex1Name, std::string tex2Name,
+ float min, float max, bool globalUpdate);
+
+ // Objects
+
//! Creates a new object and returns its rank
int CreateObject();
//! Deletes all objects, shadows and ground spots
- void FlushObject();
+ void DeleteAllObjects();
//! Deletes the given object
- bool DeleteObject(int objRank);
+ void DeleteObject(int objRank);
+
+ //@{
+ //! Management of the base object rank for engine object
+ void SetObjectBaseRank(int objRank, int baseObjRank);
+ int GetObjectBaseRank(int objRank);
+ //@}
//@{
//! Management of engine object type
- bool SetObjectType(int objRank, EngineObjectType type);
+ void SetObjectType(int objRank, EngineObjectType type);
EngineObjectType GetObjectType(int objRank);
//@}
//@{
//! Management of object transform
- bool SetObjectTransform(int objRank, const Math::Matrix& transform);
- bool GetObjectTransform(int objRank, Math::Matrix& transform);
+ void SetObjectTransform(int objRank, const Math::Matrix& transform);
+ void GetObjectTransform(int objRank, Math::Matrix& transform);
//@}
//! Sets drawWorld for given object
- bool SetObjectDrawWorld(int objRank, bool draw);
+ void SetObjectDrawWorld(int objRank, bool draw);
//! Sets drawFront for given object
- bool SetObjectDrawFront(int objRank, bool draw);
+ void SetObjectDrawFront(int objRank, bool draw);
//! Sets the transparency level for given object
- bool SetObjectTransparency(int objRank, float value);
+ void SetObjectTransparency(int objRank, float value);
//! Returns the bounding box for an object
- bool GetObjectBBox(int objRank, Math::Vector& min, Math::Vector& max);
+ void GetObjectBBox(int objRank, Math::Vector& min, Math::Vector& max);
//! Returns the total number of triangles of given object
int GetObjectTotalTriangles(int objRank);
- //! Adds triangles to given object with the specified params
- bool AddTriangles(int objRank, const std::vector<VertexTex2>& vertices,
- const Material& material, int state,
- std::string tex1Name, std::string tex2Name,
- float min, float max, bool globalUpdate);
-
- //! Adds a surface to given object with the specified params
- bool AddSurface(int objRank, const std::vector<VertexTex2>& vertices,
- const Material& material, int state,
- std::string tex1Name, std::string tex2Name,
- float min, float max, bool globalUpdate);
-
- //! Adds a tier 4 engine object directly
- bool AddQuick(int objRank, const EngineObjLevel4& buffer,
- std::string tex1Name, std::string tex2Name,
- float min, float max, bool globalUpdate);
-
//! Returns the first found tier 4 engine object for the given params or nullptr if not found
- EngineObjLevel4* FindTriangles(int objRank, const Material& material,
+ EngineBaseObjDataTier* FindTriangles(int objRank, const Material& material,
int state, std::string tex1Name, std::string tex2Name,
float min, float max);
@@ -810,16 +838,16 @@ public:
void ChangeLOD();
//! Changes the 2nd texure for given object
- bool ChangeSecondTexture(int objRank, const std::string& tex2Name);
+ void ChangeSecondTexture(int objRank, const std::string& tex2Name);
//! Changes (recalculates) texture mapping for given object
- bool ChangeTextureMapping(int objRank, const Material& mat, int state,
+ void ChangeTextureMapping(int objRank, const Material& mat, int state,
const std::string& tex1Name, const std::string& tex2Name,
float min, float max, EngineTextureMapping mode,
float au, float bu, float av, float bv);
//! Changes texture mapping for robot tracks
- bool TrackTextureMapping(int objRank, const Material& mat, int state,
+ void TrackTextureMapping(int objRank, const Material& mat, int state,
const std::string& tex1Name, const std::string& tex2Name,
float min, float max, EngineTextureMapping mode,
float pos, float factor, float tl, float ts, float tt);
@@ -829,20 +857,20 @@ public:
int DetectObject(Math::Point mouse);
//! Creates a shadow for the given object
- bool CreateShadow(int objRank);
+ void CreateShadow(int objRank);
//! Deletes the shadow for given object
void DeleteShadow(int objRank);
//@{
//! Management of different shadow params
- bool SetObjectShadowHide(int objRank, bool hide);
- bool SetObjectShadowType(int objRank, EngineShadowType type);
- bool SetObjectShadowPos(int objRank, const Math::Vector& pos);
- bool SetObjectShadowNormal(int objRank, const Math::Vector& normal);
- bool SetObjectShadowAngle(int objRank, float angle);
- bool SetObjectShadowRadius(int objRank, float radius);
- bool SetObjectShadowIntensity(int objRank, float intensity);
- bool SetObjectShadowHeight(int objRank, float height);
+ void SetObjectShadowHide(int objRank, bool hide);
+ void SetObjectShadowType(int objRank, EngineShadowType type);
+ void SetObjectShadowPos(int objRank, const Math::Vector& pos);
+ void SetObjectShadowNormal(int objRank, const Math::Vector& normal);
+ void SetObjectShadowAngle(int objRank, float angle);
+ void SetObjectShadowRadius(int objRank, float radius);
+ void SetObjectShadowIntensity(int objRank, float intensity);
+ void SetObjectShadowHeight(int objRank, float height);
float GetObjectShadowRadius(int objRank);
//@}
@@ -852,7 +880,7 @@ public:
bool GetHighlight(Math::Point& p1, Math::Point& p2);
//! Deletes all ground spots
- void FlushGroundSpot();
+ void DeleteAllGroundSpots();
//! Creates a new ground spot and returns its rank
int CreateGroundSpot();
//! Deletes the given ground spot
@@ -860,11 +888,11 @@ public:
//@{
//! Management of different ground spot params
- bool SetObjectGroundSpotPos(int rank, const Math::Vector& pos);
- bool SetObjectGroundSpotRadius(int rank, float radius);
- bool SetObjectGroundSpotColor(int rank, const Color& color);
- bool SetObjectGroundSpotMinMax(int rank, float min, float max);
- bool SetObjectGroundSpotSmooth(int rank, float smooth);
+ void SetObjectGroundSpotPos(int rank, const Math::Vector& pos);
+ void SetObjectGroundSpotRadius(int rank, float radius);
+ void SetObjectGroundSpotColor(int rank, const Color& color);
+ void SetObjectGroundSpotMinMax(int rank, float min, float max);
+ void SetObjectGroundSpotSmooth(int rank, float smooth);
//@}
//! Creates the ground mark with the given params
@@ -1157,6 +1185,8 @@ public:
protected:
//! Prepares the interface for 3D scene
void Draw3DScene();
+ //! Draw 3D object
+ void DrawObject(const EngineBaseObjDataTier& p4);
//! Draws the user interface over the scene
void DrawInterface();
@@ -1186,15 +1216,13 @@ protected:
//! Draw statistic texts
void DrawStats();
- //! Creates new tier 1 object
- EngineObjLevel1& AddLevel1(const std::string& tex1Name, const std::string& tex2Name);
- //! Creates a new tier 2 object
- EngineObjLevel2& AddLevel2(EngineObjLevel1 &p1, int objRank);
- //! Creates a new tier 3 object
- EngineObjLevel3& AddLevel3(EngineObjLevel2 &p2, float min, float max);
- //! Creates a new tier 4 object
- EngineObjLevel4& AddLevel4(EngineObjLevel3 &p3, EngineTriangleType type,
- const Material& mat, int state);
+ //! Creates a new tier 2 object (texture)
+ EngineBaseObjTexTier& AddLevel2(EngineBaseObject& p1, const std::string& tex1Name, const std::string& tex2Name);
+ //! Creates a new tier 3 object (LOD)
+ EngineBaseObjLODTier& AddLevel3(EngineBaseObjTexTier &p2, float min, float max);
+ //! Creates a new tier 4 object (data)
+ EngineBaseObjDataTier& AddLevel4(EngineBaseObjLODTier &p3, EngineTriangleType type,
+ const Material& mat, int state);
//! Create texture and add it to cache
Texture CreateTexture(const std::string &texName, const TextureCreateParams &params, CImage* image = nullptr);
@@ -1221,6 +1249,12 @@ protected:
//! Updates geometric parameters of objects (bounding box and radius)
void UpdateGeometry();
+ //! Updates a given static buffer
+ void UpdateStaticBuffer(EngineBaseObjDataTier& p4);
+
+ //! Updates static buffers of changed objects
+ void UpdateStaticBuffers();
+
protected:
CInstanceManager* m_iMan;
CApplication* m_app;
@@ -1273,8 +1307,8 @@ protected:
//! Previous size of viewport window
Math::IntPoint m_lastSize;
- //! Root of tree object structure (level 1 list)
- std::vector<EngineObjLevel1> m_objectTree;
+ //! Base objects (also level 1 tier list)
+ std::vector<EngineBaseObject> m_baseObjects;
//! Object parameters
std::vector<EngineObject> m_objects;
//! Shadow list
@@ -1299,6 +1333,7 @@ protected:
Color m_waterAddColor;
int m_statisticTriangle;
bool m_updateGeometry;
+ bool m_updateStaticBuffers;
int m_alphaMode;
bool m_groundSpotVisible;
bool m_shadowVisible;
diff --git a/src/graphics/engine/modelfile.cpp b/src/graphics/engine/modelfile.cpp
index c0d04a0..a942b08 100644
--- a/src/graphics/engine/modelfile.cpp
+++ b/src/graphics/engine/modelfile.cpp
@@ -34,22 +34,10 @@
#include <sstream>
-/*
- * NOTE: #ifndef checking for MODELFILE_NO_ENGINE
- * is provided in this module to conditionally
- * disable dependence on CEngine.
- */
-
-
// Graphics module namespace
namespace Gfx {
-//! How big the triangle vector is by default
-const int TRIANGLE_PREALLOCATE_COUNT = 2000;
-
-
-
bool ReadBinaryVertex(std::istream& stream, Vertex& vertex)
{
vertex.coord.x = IOUtils::ReadBinaryFloat(stream);
@@ -322,15 +310,8 @@ bool ReadLineString(std::istream& stream, const std::string& prefix, std::string
}
-CModelFile::CModelFile(CInstanceManager* iMan)
+CModelFile::CModelFile()
{
- m_iMan = iMan;
-
-#ifndef MODELFILE_NO_ENGINE
- m_engine = static_cast<CEngine*>(m_iMan->SearchInstance(CLASS_ENGINE));
-#endif
-
- m_triangles.reserve(TRIANGLE_PREALLOCATE_COUNT);
}
CModelFile::~CModelFile()
@@ -608,9 +589,6 @@ bool CModelFile::ReadModel(std::istream& stream)
triangle.state = t.state;
triangle.variableTex2 = t.texNum2 == 1;
- if (triangle.tex1Name == "plant.png")
- triangle.state |= ENG_RSTATE_ALPHA;
-
if (!triangle.variableTex2 && t.texNum2 != 0)
{
if (t.texNum2 >= 1 && t.texNum2 <= 10)
@@ -637,6 +615,10 @@ bool CModelFile::ReadModel(std::istream& stream)
m_triangles[i].tex2Name = StrUtils::Replace(m_triangles[i].tex2Name, "bmp", "png");
m_triangles[i].tex2Name = StrUtils::Replace(m_triangles[i].tex2Name, "tga", "png");
+ // TODO: fix this in model files
+ if (m_triangles[i].tex1Name == "plant.png")
+ m_triangles[i].state |= ENG_RSTATE_ALPHA;
+
GetLogger()->Trace("ModelTriangle %d\n", i+1);
std::string s1 = m_triangles[i].p1.ToString();
GetLogger()->Trace(" p1: %s\n", s1.c_str());
@@ -1154,93 +1136,6 @@ bool CModelFile::WriteBinaryModel(std::ostream& stream)
Other stuff
*******************************************************/
-#ifndef MODELFILE_NO_ENGINE
-
-bool CModelFile::CreateEngineObject(int objRank)
-{
- std::vector<VertexTex2> vs(3, VertexTex2());
-
- float limit[2];
- limit[0] = m_engine->GetLimitLOD(0); // frontier AB as config
- limit[1] = m_engine->GetLimitLOD(1); // frontier BC as config
-
- for (int i = 0; i < static_cast<int>( m_triangles.size() ); i++)
- {
- // TODO move this to CEngine
-
- float min = m_triangles[i].min;
- float max = m_triangles[i].max;
-
- // Standard frontiers -> config
- if (min == 0.0f && max == 100.0f) // resolution A ?
- {
- max = limit[0];
- }
- else if (min == 100.0f && max == 200.0f) // resolution B ?
- {
- min = limit[0];
- max = limit[1];
- }
- else if (min == 200.0f && max == 1000000.0f) // resolution C ?
- {
- min = limit[1];
- }
-
- int state = m_triangles[i].state;
- std::string tex2Name = m_triangles[i].tex2Name;
-
- if (m_triangles[i].variableTex2)
- {
- int texNum = m_engine->GetSecondTexture();
-
- if (texNum >= 1 && texNum <= 10)
- state |= ENG_RSTATE_DUAL_BLACK;
-
- if (texNum >= 11 && texNum <= 20)
- state |= ENG_RSTATE_DUAL_WHITE;
-
- char name[20] = { 0 };
- sprintf(name, "dirty%.2d.png", texNum);
- tex2Name = name;
- }
-
- vs[0] = m_triangles[i].p1;
- vs[1] = m_triangles[i].p2;
- vs[2] = m_triangles[i].p3;
-
- bool ok = m_engine->AddTriangles(objRank, vs,
- m_triangles[i].material,
- state,
- m_triangles[i].tex1Name,
- tex2Name,
- min, max, false);
- if (!ok)
- return false;
- }
-
- return true;
-}
-
-#endif
-
-void CModelFile::Mirror()
-{
- for (int i = 0; i < static_cast<int>( m_triangles.size() ); i++)
- {
- VertexTex2 t = m_triangles[i].p1;
- m_triangles[i].p1 = m_triangles[i].p2;
- m_triangles[i].p2 = t;
-
- m_triangles[i].p1.coord.z = -m_triangles[i].p1.coord.z;
- m_triangles[i].p2.coord.z = -m_triangles[i].p2.coord.z;
- m_triangles[i].p3.coord.z = -m_triangles[i].p3.coord.z;
-
- m_triangles[i].p1.normal.z = -m_triangles[i].p1.normal.z;
- m_triangles[i].p2.normal.z = -m_triangles[i].p2.normal.z;
- m_triangles[i].p3.normal.z = -m_triangles[i].p3.normal.z;
- }
-}
-
const std::vector<ModelTriangle>& CModelFile::GetTriangles()
{
return m_triangles;
@@ -1251,28 +1146,6 @@ int CModelFile::GetTriangleCount()
return m_triangles.size();
}
-float CModelFile::GetHeight(Math::Vector pos)
-{
- float limit = 5.0f;
-
- for (int i = 0; i < static_cast<int>( m_triangles.size() ); i++)
- {
- if ( fabs(pos.x - m_triangles[i].p1.coord.x) < limit &&
- fabs(pos.z - m_triangles[i].p1.coord.z) < limit )
- return m_triangles[i].p1.coord.y;
-
- if ( fabs(pos.x - m_triangles[i].p2.coord.x) < limit &&
- fabs(pos.z - m_triangles[i].p2.coord.z) < limit )
- return m_triangles[i].p2.coord.y;
-
- if ( fabs(pos.x - m_triangles[i].p3.coord.x) < limit &&
- fabs(pos.z - m_triangles[i].p3.coord.z) < limit )
- return m_triangles[i].p3.coord.y;
- }
-
- return 0.0f;
-}
-
void CModelFile::CreateTriangle(Math::Vector p1, Math::Vector p2, Math::Vector p3, float min, float max)
{
ModelTriangle triangle;
diff --git a/src/graphics/engine/modelfile.h b/src/graphics/engine/modelfile.h
index 6c573b8..b2b5d87 100644
--- a/src/graphics/engine/modelfile.h
+++ b/src/graphics/engine/modelfile.h
@@ -33,14 +33,10 @@
#include <iostream>
-class CInstanceManager;
-
// Graphics module namespace
namespace Gfx {
-class CEngine;
-
/**
\struct ModelTriangle
@@ -79,14 +75,15 @@ struct ModelTriangle
/**
- \class CModelFile
- \brief Model file reader/writer
-
- Allows reading and writing model objects. Models are collections of ModelTriangle structs. */
+ * \class CModelFile
+ * \brief Model file reader/writer
+ *
+ * Allows reading and writing model objects. Models are collections of ModelTriangle structs.
+ */
class CModelFile
{
public:
- CModelFile(CInstanceManager* iMan);
+ CModelFile();
~CModelFile();
//! Reads a model in text format from file
@@ -128,23 +125,11 @@ public:
//! Returns the triangle vector
const std::vector<ModelTriangle>& GetTriangles();
- //! Returns the height of model -- closest point to X and Z coords of \a pos
- float GetHeight(Math::Vector pos);
-
- //! Mirrors the model along the Z axis
- void Mirror();
-
- //! Creates an object in the graphics engine from the model
- bool CreateEngineObject(int objRank);
-
protected:
//! Adds a triangle to the list
void CreateTriangle(Math::Vector p1, Math::Vector p2, Math::Vector p3, float min, float max);
protected:
- CInstanceManager* m_iMan;
- CEngine* m_engine;
-
//! Model triangles
std::vector<ModelTriangle> m_triangles;
};
diff --git a/src/graphics/engine/modelmanager.cpp b/src/graphics/engine/modelmanager.cpp
new file mode 100644
index 0000000..afaa718
--- /dev/null
+++ b/src/graphics/engine/modelmanager.cpp
@@ -0,0 +1,213 @@
+#include "graphics/engine/modelmanager.h"
+
+#include "app/app.h"
+
+#include "common/logger.h"
+
+#include "graphics/engine/engine.h"
+
+#include <cstdio>
+
+namespace Gfx {
+
+template<> CModelManager* CSingleton<CModelManager>::mInstance = nullptr;
+
+CModelManager::CModelManager(CEngine* engine)
+{
+ m_engine = engine;
+}
+
+CModelManager::~CModelManager()
+{
+}
+
+bool CModelManager::LoadModel(const std::string& fileName, bool mirrored)
+{
+ GetLogger()->Info("Loading model '%s'\n", fileName.c_str());
+
+ CModelFile modelFile;
+
+ std::string filePath = CApplication::GetInstance().GetDataFilePath(DIR_MODEL, fileName);
+
+ if (!modelFile.ReadModel(filePath))
+ {
+ GetLogger()->Error("Loading model '%s' failed\n", filePath.c_str());
+ return false;
+ }
+
+ ModelInfo modelInfo;
+ modelInfo.baseObjRank = m_engine->CreateBaseObject();
+ modelInfo.triangles = modelFile.GetTriangles();
+
+ if (mirrored)
+ Mirror(modelInfo.triangles);
+
+ FileInfo fileInfo(fileName, mirrored);
+ m_models[fileInfo] = modelInfo;
+
+ std::vector<VertexTex2> vs(3, VertexTex2());
+
+ float limit[2];
+ limit[0] = m_engine->GetLimitLOD(0); // frontier AB as config
+ limit[1] = m_engine->GetLimitLOD(1); // frontier BC as config
+
+ for (int i = 0; i < static_cast<int>( modelInfo.triangles.size() ); i++)
+ {
+ float min = modelInfo.triangles[i].min;
+ float max = modelInfo.triangles[i].max;
+
+ // Standard frontiers -> config
+ if (min == 0.0f && max == 100.0f) // resolution A ?
+ {
+ max = limit[0];
+ }
+ else if (min == 100.0f && max == 200.0f) // resolution B ?
+ {
+ min = limit[0];
+ max = limit[1];
+ }
+ else if (min == 200.0f && max == 1000000.0f) // resolution C ?
+ {
+ min = limit[1];
+ }
+
+ int state = modelInfo.triangles[i].state;
+ std::string tex2Name = modelInfo.triangles[i].tex2Name;
+
+ if (modelInfo.triangles[i].variableTex2)
+ {
+ int texNum = m_engine->GetSecondTexture();
+
+ if (texNum >= 1 && texNum <= 10)
+ state |= ENG_RSTATE_DUAL_BLACK;
+
+ if (texNum >= 11 && texNum <= 20)
+ state |= ENG_RSTATE_DUAL_WHITE;
+
+ char name[20] = { 0 };
+ sprintf(name, "dirty%.2d.png", texNum);
+ tex2Name = name;
+ }
+
+ vs[0] = modelInfo.triangles[i].p1;
+ vs[1] = modelInfo.triangles[i].p2;
+ vs[2] = modelInfo.triangles[i].p3;
+
+ m_engine->AddBaseObjTriangles(modelInfo.baseObjRank, vs, ENG_TRIANGLE_TYPE_TRIANGLES,
+ modelInfo.triangles[i].material, state,
+ modelInfo.triangles[i].tex1Name, tex2Name,
+ min, max, false);
+ }
+
+ return true;
+}
+
+bool CModelManager::AddModelReference(const std::string& fileName, bool mirrored, int objRank)
+{
+ auto it = m_models.find(FileInfo(fileName, mirrored));
+ if (it == m_models.end())
+ {
+ if (!LoadModel(fileName, mirrored))
+ return false;
+
+ it = m_models.find(FileInfo(fileName, mirrored));
+ }
+
+ m_engine->SetObjectBaseRank(objRank, (*it).second.baseObjRank);
+
+ return true;
+}
+
+bool CModelManager::AddModelCopy(const std::string& fileName, bool mirrored, int objRank)
+{
+ auto it = m_models.find(FileInfo(fileName, mirrored));
+ if (it == m_models.end())
+ {
+ if (!LoadModel(fileName, mirrored))
+ return false;
+
+ it = m_models.find(FileInfo(fileName, mirrored));
+ }
+
+ int copyBaseObjRank = m_engine->CreateBaseObject();
+ m_engine->CopyBaseObject((*it).second.baseObjRank, copyBaseObjRank);
+ m_engine->SetObjectBaseRank(objRank, copyBaseObjRank);
+
+ return true;
+}
+
+bool CModelManager::IsModelLoaded(const std::string& fileName, bool mirrored)
+{
+ return m_models.count(FileInfo(fileName, mirrored)) > 0;
+}
+
+int CModelManager::GetModelBaseObjRank(const std::string& fileName, bool mirrored)
+{
+ auto it = m_models.find(FileInfo(fileName, mirrored));
+ if (it == m_models.end())
+ return -1;
+
+ return (*it).second.baseObjRank;
+}
+
+void CModelManager::UnloadModel(const std::string& fileName, bool mirrored)
+{
+ auto it = m_models.find(FileInfo(fileName, mirrored));
+ if (it == m_models.end())
+ return;
+
+ m_engine->DeleteBaseObject((*it).second.baseObjRank);
+
+ m_models.erase(it);
+}
+
+void CModelManager::UnloadAllModels()
+{
+ for (auto& mf : m_models)
+ m_engine->DeleteBaseObject(mf.second.baseObjRank);
+
+ m_models.clear();
+}
+
+void CModelManager::Mirror(std::vector<ModelTriangle>& triangles)
+{
+ for (int i = 0; i < static_cast<int>( triangles.size() ); i++)
+ {
+ VertexTex2 t = triangles[i].p1;
+ triangles[i].p1 = triangles[i].p2;
+ triangles[i].p2 = t;
+
+ triangles[i].p1.coord.z = -triangles[i].p1.coord.z;
+ triangles[i].p2.coord.z = -triangles[i].p2.coord.z;
+ triangles[i].p3.coord.z = -triangles[i].p3.coord.z;
+
+ triangles[i].p1.normal.z = -triangles[i].p1.normal.z;
+ triangles[i].p2.normal.z = -triangles[i].p2.normal.z;
+ triangles[i].p3.normal.z = -triangles[i].p3.normal.z;
+ }
+}
+
+float CModelManager::GetHeight(std::vector<ModelTriangle>& triangles, Math::Vector pos)
+{
+ const float limit = 5.0f;
+
+ for (int i = 0; i < static_cast<int>( triangles.size() ); i++)
+ {
+ if ( fabs(pos.x - triangles[i].p1.coord.x) < limit &&
+ fabs(pos.z - triangles[i].p1.coord.z) < limit )
+ return triangles[i].p1.coord.y;
+
+ if ( fabs(pos.x - triangles[i].p2.coord.x) < limit &&
+ fabs(pos.z - triangles[i].p2.coord.z) < limit )
+ return triangles[i].p2.coord.y;
+
+ if ( fabs(pos.x - triangles[i].p3.coord.x) < limit &&
+ fabs(pos.z - triangles[i].p3.coord.z) < limit )
+ return triangles[i].p3.coord.y;
+ }
+
+ return 0.0f;
+}
+
+
+}
diff --git a/src/graphics/engine/modelmanager.h b/src/graphics/engine/modelmanager.h
new file mode 100644
index 0000000..601d636
--- /dev/null
+++ b/src/graphics/engine/modelmanager.h
@@ -0,0 +1,97 @@
+#pragma once
+
+#include "common/singleton.h"
+
+#include "graphics/engine/modelfile.h"
+
+#include <string>
+#include <vector>
+#include <map>
+
+namespace Gfx {
+
+class CEngine;
+class CModelFile;
+
+/**
+ * \class CModelManager
+ * \brief Manager for static models
+ *
+ * The manager allows for loading models as static objects and adding
+ * new instances of models to the engine.
+ *
+ * The models are loaded from stanard application model directory and
+ * they are identified by unique file names.
+ *
+ * The models are loaded by creating (if it doesn't exist yet)
+ * a base engine object from the model geometry. This base object
+ * is then shared among all instances of this model with the instances
+ * being engine objects linked to the shared base object.
+ *
+ * There is also a possibility of creating a copy of model so it has
+ * its own and unique base engine object. This is especially useful
+ * for models where the geometry must be altered.
+ */
+class CModelManager : public CSingleton<CModelManager>
+{
+public:
+ CModelManager(CEngine* engine);
+ ~CModelManager();
+
+ //! Loads a model from given file
+ bool LoadModel(const std::string& fileName, bool mirrored);
+
+ //! Adds an instance of model to the given object rank as a reference to base object
+ bool AddModelReference(const std::string& fileName, bool mirrored, int objRank);
+
+ //! Adds an instance of model to the given object rank as a copy (copied base object)
+ bool AddModelCopy(const std::string& fileName, bool mirrored, int objRank);
+
+ //! Returns true if given model is loaded
+ bool IsModelLoaded(const std::string& fileName, bool mirrored);
+
+ //! Returns the rank of base engine object of given loaded model
+ int GetModelBaseObjRank(const std::string& fileName, bool mirrored);
+
+ //! Unloads the given model
+ void UnloadModel(const std::string& fileName, bool mirrored);
+ //! Unloads all models
+ void UnloadAllModels();
+
+protected:
+ //! Returns the height of model -- closest point to X and Z coords of \a pos
+ float GetHeight(std::vector<ModelTriangle>& triangles, Math::Vector pos);
+
+ //! Mirrors the model along the Z axis
+ void Mirror(std::vector<ModelTriangle>& triangles);
+
+private:
+ struct ModelInfo
+ {
+ std::vector<ModelTriangle> triangles;
+ int baseObjRank;
+ };
+ struct FileInfo
+ {
+ std::string fileName;
+ bool mirrored;
+
+ inline FileInfo(const std::string& fileName, bool mirrored)
+ : fileName(fileName), mirrored(mirrored) {}
+
+ inline bool operator<(const FileInfo& other) const
+ {
+ int compare = fileName.compare(other.fileName);
+ if (compare < 0)
+ return true;
+ if (compare > 0)
+ return false;
+
+ return !mirrored && mirrored != other.mirrored;
+ }
+ };
+ std::map<FileInfo, ModelInfo> m_models;
+ CEngine* m_engine;
+};
+
+} // namespace Gfx
diff --git a/src/graphics/engine/particle.cpp b/src/graphics/engine/particle.cpp
index acc40df..388c189 100644
--- a/src/graphics/engine/particle.cpp
+++ b/src/graphics/engine/particle.cpp
@@ -3214,7 +3214,7 @@ void CParticle::DrawParticleSphere(int i)
angle.z = m_particle[i].angle*0.7f;
Math::Matrix rot;
Math::LoadRotationZXYMatrix(rot, angle);
- mat = Math::MultiplyMatrices(rot, mat);
+ mat = Math::MultiplyMatrices(mat, rot);
}
m_device->SetTransform(TRANSFORM_WORLD, mat);
diff --git a/src/graphics/engine/terrain.cpp b/src/graphics/engine/terrain.cpp
index 4c22a32..a66b4b0 100644
--- a/src/graphics/engine/terrain.cpp
+++ b/src/graphics/engine/terrain.cpp
@@ -34,10 +34,6 @@
// Graphics module namespace
namespace Gfx {
-const int LEVEL_MAT_PREALLOCATE_COUNT = 101;
-const int FLYING_LIMIT_PREALLOCATE_COUNT = 10;
-const int BUILDING_LEVEL_PREALLOCATE_COUNT = 101;
-
CTerrain::CTerrain(CInstanceManager* iMan)
{
@@ -60,10 +56,6 @@ CTerrain::CTerrain(CInstanceManager* iMan)
m_defaultHardness = 0.5f;
m_useMaterials = false;
- m_materials.reserve(LEVEL_MAT_PREALLOCATE_COUNT);
- m_flyingLimits.reserve(FLYING_LIMIT_PREALLOCATE_COUNT);
- m_buildingLevels.reserve(BUILDING_LEVEL_PREALLOCATE_COUNT);
-
FlushBuildingLevel();
FlushFlyingLimit();
FlushMaterials();
@@ -478,6 +470,8 @@ VertexTex2 CTerrain::GetVertex(int x, int y, int step)
v.texCoord.x = (o.x-oo.x)*m_textureScale*m_textureSubdivCount;
v.texCoord.y = 1.0f - (o.z-oo.z)*m_textureScale*m_textureSubdivCount;
+ v.texCoord2 = v.texCoord;
+
return v;
}
@@ -496,6 +490,13 @@ bool CTerrain::CreateMosaic(int ox, int oy, int step, int objRank,
const Material &mat,
float min, float max)
{
+ int baseObjRank = m_engine->GetObjectBaseRank(objRank);
+ if (baseObjRank == -1)
+ {
+ baseObjRank = m_engine->CreateBaseObject();
+ m_engine->SetObjectBaseRank(objRank, baseObjRank);
+ }
+
std::string texName1;
std::string texName2;
@@ -545,7 +546,7 @@ bool CTerrain::CreateMosaic(int ox, int oy, int step, int objRank,
for (int y = 0; y < brick; y += step)
{
- EngineObjLevel4 buffer;
+ EngineBaseObjDataTier buffer;
buffer.vertices.reserve(total);
buffer.type = ENG_TRIANGLE_TYPE_SURFACE;
@@ -638,7 +639,8 @@ bool CTerrain::CreateMosaic(int ox, int oy, int step, int objRank,
buffer.vertices.push_back(p1);
buffer.vertices.push_back(p2);
}
- m_engine->AddQuick(objRank, buffer, texName1, texName2, min, max, true);
+
+ m_engine->AddBaseObjQuick(baseObjRank, buffer, texName1, texName2, min, max, true);
}
}
}
@@ -1272,7 +1274,10 @@ bool CTerrain::Terraform(const Math::Vector &p1, const Math::Vector &p2, float h
{
for (int x = pp1.x; x <= pp2.x; x++)
{
- m_engine->DeleteObject(m_objRanks[x+y*m_mosaicCount]);
+ int objRank = m_objRanks[x+y*m_mosaicCount];
+ int baseObjRank = m_engine->GetObjectBaseRank(objRank);
+ m_engine->DeleteBaseObject(baseObjRank);
+ m_engine->DeleteObject(objRank);
CreateSquare(x, y); // recreates the square
}
}
diff --git a/src/graphics/engine/terrain.h b/src/graphics/engine/terrain.h
index 3012e62..e17144e 100644
--- a/src/graphics/engine/terrain.h
+++ b/src/graphics/engine/terrain.h
@@ -328,7 +328,7 @@ protected:
//! Calculates a vector of the terrain
Math::Vector GetVector(int x, int y);
//! Calculates a vertex of the terrain
- VertexTex2 GetVertex(int x, int y, int step);
+ VertexTex2 GetVertex(int x, int y, int step);
//! Creates all objects of a mosaic
bool CreateMosaic(int ox, int oy, int step, int objRank, const Material& mat, float min, float max);
//! Creates all objects in a mesh square ground
diff --git a/src/graphics/engine/test/CMakeLists.txt b/src/graphics/engine/test/CMakeLists.txt
index 46509f4..afaa86a 100644
--- a/src/graphics/engine/test/CMakeLists.txt
+++ b/src/graphics/engine/test/CMakeLists.txt
@@ -3,7 +3,6 @@ cmake_minimum_required(VERSION 2.8)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE debug)
endif(NOT CMAKE_BUILD_TYPE)
-set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wold-style-cast -std=gnu++0x")
set(CMAKE_CXX_FLAGS_DEBUG "-g -O0")
set(MODELFILE_TEST_SOURCES
@@ -11,7 +10,6 @@ modelfile_test.cpp
../modelfile.cpp
../../../common/logger.cpp
../../../common/stringutils.cpp
-../../../common/iman.cpp
)
add_definitions(-DMODELFILE_NO_ENGINE)
diff --git a/src/graphics/engine/test/modelfile_test.cpp b/src/graphics/engine/test/modelfile_test.cpp
index 6879a1b..43cd43b 100644
--- a/src/graphics/engine/test/modelfile_test.cpp
+++ b/src/graphics/engine/test/modelfile_test.cpp
@@ -15,12 +15,11 @@
// * along with this program. If not, see http://www.gnu.org/licenses/.
-#include "common/iman.h"
#include "common/logger.h"
#include "graphics/engine/modelfile.h"
#include "math/func.h"
-#include "gtest/gtest.h"
+#include <gtest/gtest.h>
#include <cassert>
#include <sstream>
@@ -190,8 +189,7 @@ TEST(ModelFileTest, RWTxtModel)
std::stringstream str;
str.str(TEXT_MODEL);
- CInstanceManager iMan;
- Gfx::CModelFile modelFile(&iMan);
+ Gfx::CModelFile modelFile;
EXPECT_TRUE(modelFile.ReadTextModel(str));
@@ -216,8 +214,7 @@ TEST(ModelFileTest, RWBinModel)
std::stringstream str;
str.str(TEXT_MODEL);
- CInstanceManager iMan;
- Gfx::CModelFile modelFile(&iMan);
+ Gfx::CModelFile modelFile;
EXPECT_TRUE(modelFile.ReadTextModel(str));
@@ -242,8 +239,7 @@ TEST(ModelFileTest, RWOldModel)
std::stringstream str;
str.str(TEXT_MODEL);
- CInstanceManager iMan;
- Gfx::CModelFile modelFile(&iMan);
+ Gfx::CModelFile modelFile;
EXPECT_TRUE(modelFile.ReadTextModel(str));
diff --git a/src/graphics/engine/text.cpp b/src/graphics/engine/text.cpp
index 101e01a..da1a290 100644
--- a/src/graphics/engine/text.cpp
+++ b/src/graphics/engine/text.cpp
@@ -46,7 +46,7 @@ struct CachedFont
};
-
+const Math::IntPoint REFERENCE_SIZE(800, 600);
CText::CText(CInstanceManager *iMan, CEngine* engine)
@@ -147,6 +147,10 @@ void CText::FlushCache()
f->cache.clear();
}
}
+
+ m_lastFontType = FONT_COLOBOT;
+ m_lastFontSize = 0;
+ m_lastCachedFont = nullptr;
}
void CText::DrawText(const std::string &text, std::map<unsigned int, FontMetaChar> &format,
@@ -723,8 +727,8 @@ void CText::DrawCharAndAdjustPos(UTF8Char ch, FontType font, float size, Math::P
CachedFont* CText::GetOrOpenFont(FontType font, float size)
{
- // TODO: sizing
- int pointSize = static_cast<int>(size);
+ Math::IntPoint windowSize = m_engine->GetWindowSize();
+ int pointSize = static_cast<int>(size * (windowSize.Length() / REFERENCE_SIZE.Length()));
if (m_lastCachedFont != nullptr)
{
diff --git a/src/graphics/engine/water.cpp b/src/graphics/engine/water.cpp
index 18811eb..6c822b3 100644
--- a/src/graphics/engine/water.cpp
+++ b/src/graphics/engine/water.cpp
@@ -386,9 +386,11 @@ void CWater::DrawSurf()
Math::Vector p = pos;
p.x += size*(m_lines[i].len-1);
float radius = sqrtf(powf(size, 2.0f)+powf(size*m_lines[i].len, 2.0f));
- if ( Math::Distance(p, eye) > deep+radius ) continue;
+ if (Math::Distance(p, eye) > deep + radius)
+ continue;
- // TODO: ComputeSphereVisibility
+ if (device->ComputeSphereVisibility(p, radius) != Gfx::FRUSTUM_PLANE_ALL)
+ continue;
int vertexIndex = 0;
diff --git a/src/graphics/opengl/gldevice.cpp b/src/graphics/opengl/gldevice.cpp
index 94b0dbc..80fa9a1 100644
--- a/src/graphics/opengl/gldevice.cpp
+++ b/src/graphics/opengl/gldevice.cpp
@@ -24,22 +24,9 @@
#include "math/geometry.h"
-#if defined(USE_GLEW)
-
-// When using GLEW, only glew.h is needed
+// Using GLEW so only glew.h is needed
#include <GL/glew.h>
-#else
-
-// Should define prototypes of used extensions as OpenGL functions
-#define GL_GLEXT_PROTOTYPES
-
-#include <GL/gl.h>
-#include <GL/glu.h>
-#include <GL/glext.h>
-
-#endif // if defined(GLEW)
-
#include <SDL/SDL.h>
#include <cassert>
@@ -73,6 +60,9 @@ CGLDevice::CGLDevice(const GLDeviceConfig &config)
{
m_config = config;
m_lighting = false;
+ m_lastVboId = 0;
+ m_multitextureAvailable = false;
+ m_vboAvailable = false;
}
@@ -91,29 +81,30 @@ bool CGLDevice::Create()
{
GetLogger()->Info("Creating CDevice\n");
-#if defined(USE_GLEW)
static bool glewInited = false;
if (!glewInited)
{
glewInited = true;
+ glewExperimental = GL_TRUE;
+
if (glewInit() != GLEW_OK)
{
GetLogger()->Error("GLEW initialization failed\n");
return false;
}
- if ( (! GLEW_ARB_multitexture) || (! GLEW_EXT_texture_env_combine) )
- {
- GetLogger()->Error("GLEW reports required extensions not supported\n");
- return false;
- }
- }
-#endif
+ m_multitextureAvailable = glewIsSupported("GL_ARB_multitexture GL_ARB_texture_env_combine");
+ if (!m_multitextureAvailable)
+ GetLogger()->Warn("GLEW reports multitexturing not supported - graphics quality will be degraded!\n");
- /* NOTE: when not using GLEW, extension testing is not performed, as it is assumed that
- glext.h is up-to-date and the OpenGL shared library has the required functions present. */
+ m_vboAvailable = glewIsSupported("GL_ARB_vertex_buffer_object");
+ if (m_vboAvailable)
+ GetLogger()->Info("Detected ARB_vertex_buffer_object extension - using VBOs\n");
+ else
+ GetLogger()->Info("No ARB_vertex_buffer_object extension present - using display lists\n");
+ }
// This is mostly done in all modern hardware by default
// DirectX doesn't even allow the option to turn off perspective correction anymore
@@ -123,6 +114,9 @@ bool CGLDevice::Create()
// To avoid problems with scaling & lighting
glEnable(GL_RESCALE_NORMAL);
+ // Minimal depth bias to avoid Z-fighting
+ SetDepthBias(0.001f);
+
// Set just to be sure
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glMatrixMode(GL_PROJECTION);
@@ -174,6 +168,16 @@ void CGLDevice::ConfigChanged(const GLDeviceConfig& newConfig)
Create();
}
+void CGLDevice::SetUseVbo(bool vboAvailable)
+{
+ m_vboAvailable = vboAvailable;
+}
+
+bool CGLDevice::GetUseVbo()
+{
+ return m_vboAvailable;
+}
+
void CGLDevice::BeginScene()
{
Clear();
@@ -413,7 +417,9 @@ Texture CGLDevice::CreateTexture(ImageData *data, const TextureCreateParams &par
result.size.y = data->surface->h;
// Use & enable 1st texture stage
- glActiveTexture(GL_TEXTURE0);
+ if (m_multitextureAvailable)
+ glActiveTexture(GL_TEXTURE0);
+
glEnable(GL_TEXTURE_2D);
glGenTextures(1, &result.id);
@@ -588,7 +594,7 @@ void CGLDevice::DestroyAllTextures()
m_allTextures.clear();
}
-int CGLDevice::GetMaxTextureCount()
+int CGLDevice::GetMaxTextureStageCount()
{
return m_currentTextures.size();
}
@@ -599,17 +605,21 @@ int CGLDevice::GetMaxTextureCount()
The setting is remembered, even if texturing is disabled at the moment. */
void CGLDevice::SetTexture(int index, const Texture &texture)
{
- assert(index >= 0);
- assert(index < static_cast<int>( m_currentTextures.size() ));
+ assert(index >= 0 && index < static_cast<int>( m_currentTextures.size() ));
bool same = m_currentTextures[index].id == texture.id;
m_currentTextures[index] = texture; // remember the new value
+ if (!m_multitextureAvailable && index != 0)
+ return;
+
if (same)
return; // nothing to do
- glActiveTexture(GL_TEXTURE0 + index);
+ if (m_multitextureAvailable)
+ glActiveTexture(GL_TEXTURE0 + index);
+
glBindTexture(GL_TEXTURE_2D, texture.id);
// Params need to be updated for the new bound texture
@@ -618,15 +628,19 @@ void CGLDevice::SetTexture(int index, const Texture &texture)
void CGLDevice::SetTexture(int index, unsigned int textureId)
{
- assert(index >= 0);
- assert(index < static_cast<int>( m_currentTextures.size() ));
+ assert(index >= 0 && index < static_cast<int>( m_currentTextures.size() ));
if (m_currentTextures[index].id == textureId)
return; // nothing to do
m_currentTextures[index].id = textureId;
- glActiveTexture(GL_TEXTURE0 + index);
+ if (!m_multitextureAvailable && index != 0)
+ return;
+
+ if (m_multitextureAvailable)
+ glActiveTexture(GL_TEXTURE0 + index);
+
glBindTexture(GL_TEXTURE_2D, textureId);
// Params need to be updated for the new bound texture
@@ -637,16 +651,14 @@ void CGLDevice::SetTexture(int index, unsigned int textureId)
Returns the previously assigned texture or invalid texture if the given stage is not enabled. */
Texture CGLDevice::GetTexture(int index)
{
- assert(index >= 0);
- assert(index < static_cast<int>( m_currentTextures.size() ));
+ assert(index >= 0 && index < static_cast<int>( m_currentTextures.size() ));
return m_currentTextures[index];
}
void CGLDevice::SetTextureEnabled(int index, bool enabled)
{
- assert(index >= 0);
- assert(index < static_cast<int>( m_currentTextures.size() ));
+ assert(index >= 0 && index < static_cast<int>( m_currentTextures.size() ));
bool same = m_texturesEnabled[index] == enabled;
@@ -655,7 +667,12 @@ void CGLDevice::SetTextureEnabled(int index, bool enabled)
if (same)
return; // nothing to do
- glActiveTexture(GL_TEXTURE0 + index);
+ if (!m_multitextureAvailable && index != 0)
+ return;
+
+ if (m_multitextureAvailable)
+ glActiveTexture(GL_TEXTURE0 + index);
+
if (enabled)
glEnable(GL_TEXTURE_2D);
else
@@ -664,8 +681,7 @@ void CGLDevice::SetTextureEnabled(int index, bool enabled)
bool CGLDevice::GetTextureEnabled(int index)
{
- assert(index >= 0);
- assert(index < static_cast<int>( m_currentTextures.size() ));
+ assert(index >= 0 && index < static_cast<int>( m_currentTextures.size() ));
return m_texturesEnabled[index];
}
@@ -676,17 +692,36 @@ bool CGLDevice::GetTextureEnabled(int index)
The settings are remembered, even if texturing is disabled at the moment. */
void CGLDevice::SetTextureStageParams(int index, const TextureStageParams &params)
{
- assert(index >= 0);
- assert(index < static_cast<int>( m_currentTextures.size() ));
+ assert(index >= 0 && index < static_cast<int>( m_currentTextures.size() ));
// Remember the settings
m_textureStageParams[index] = params;
+ if (!m_multitextureAvailable && index != 0)
+ return;
+
// Don't actually do anything if texture not set
if (! m_currentTextures[index].Valid())
return;
- glActiveTexture(GL_TEXTURE0 + index);
+ if (m_multitextureAvailable)
+ glActiveTexture(GL_TEXTURE0 + index);
+
+ if (params.wrapS == TEX_WRAP_CLAMP)
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
+ else if (params.wrapS == TEX_WRAP_REPEAT)
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
+ else assert(false);
+
+ if (params.wrapT == TEX_WRAP_CLAMP)
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
+ else if (params.wrapT == TEX_WRAP_REPEAT)
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
+ else assert(false);
+
+ // Texture env setting is silly without multitexturing
+ if (!m_multitextureAvailable)
+ return;
glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, params.factor.Array());
@@ -790,26 +825,12 @@ after_tex_color:
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_ALPHA, GL_CONSTANT);
else assert(false);
-
-after_tex_operations:
-
- if (params.wrapS == TEX_WRAP_CLAMP)
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
- else if (params.wrapS == TEX_WRAP_REPEAT)
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
- else assert(false);
-
- if (params.wrapT == TEX_WRAP_CLAMP)
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
- else if (params.wrapT == TEX_WRAP_REPEAT)
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
- else assert(false);
+after_tex_operations: ;
}
void CGLDevice::SetTextureStageWrap(int index, TexWrapMode wrapS, TexWrapMode wrapT)
{
- assert(index >= 0);
- assert(index < static_cast<int>( m_currentTextures.size() ));
+ assert(index >= 0 && index < static_cast<int>( m_currentTextures.size() ));
// Remember the settings
m_textureStageParams[index].wrapS = wrapS;
@@ -819,7 +840,11 @@ void CGLDevice::SetTextureStageWrap(int index, TexWrapMode wrapS, TexWrapMode wr
if (! m_currentTextures[index].Valid())
return;
- glActiveTexture(GL_TEXTURE0 + index);
+ if (!m_multitextureAvailable && index != 0)
+ return;
+
+ if (m_multitextureAvailable)
+ glActiveTexture(GL_TEXTURE0 + index);
if (wrapS == TEX_WRAP_CLAMP)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
@@ -836,8 +861,7 @@ void CGLDevice::SetTextureStageWrap(int index, TexWrapMode wrapS, TexWrapMode wr
TextureStageParams CGLDevice::GetTextureStageParams(int index)
{
- assert(index >= 0);
- assert(index < static_cast<int>( m_currentTextures.size() ));
+ assert(index >= 0 && index < static_cast<int>( m_currentTextures.size() ));
return m_textureStageParams[index];
}
@@ -868,7 +892,9 @@ void CGLDevice::DrawPrimitive(PrimitiveType type, const Vertex *vertices, int ve
glEnableClientState(GL_NORMAL_ARRAY);
glNormalPointer(GL_FLOAT, sizeof(Vertex), reinterpret_cast<GLfloat*>(&vs[0].normal));
- glClientActiveTexture(GL_TEXTURE0);
+ if (m_multitextureAvailable)
+ glClientActiveTexture(GL_TEXTURE0);
+
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glTexCoordPointer(2, GL_FLOAT, sizeof(Vertex), reinterpret_cast<GLfloat*>(&vs[0].texCoord));
@@ -892,13 +918,18 @@ void CGLDevice::DrawPrimitive(PrimitiveType type, const VertexTex2 *vertices, in
glEnableClientState(GL_NORMAL_ARRAY);
glNormalPointer(GL_FLOAT, sizeof(VertexTex2), reinterpret_cast<GLfloat*>(&vs[0].normal));
- glClientActiveTexture(GL_TEXTURE0);
+ if (m_multitextureAvailable)
+ glClientActiveTexture(GL_TEXTURE0);
+
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glTexCoordPointer(2, GL_FLOAT, sizeof(VertexTex2), reinterpret_cast<GLfloat*>(&vs[0].texCoord));
- glClientActiveTexture(GL_TEXTURE1);
- glEnableClientState(GL_TEXTURE_COORD_ARRAY);
- glTexCoordPointer(2, GL_FLOAT, sizeof(VertexTex2), reinterpret_cast<GLfloat*>(&vs[0].texCoord2));
+ if (m_multitextureAvailable)
+ {
+ glClientActiveTexture(GL_TEXTURE1);
+ glEnableClientState(GL_TEXTURE_COORD_ARRAY);
+ glTexCoordPointer(2, GL_FLOAT, sizeof(VertexTex2), reinterpret_cast<GLfloat*>(&vs[0].texCoord2));
+ }
glColor4fv(color.Array());
@@ -907,8 +938,11 @@ void CGLDevice::DrawPrimitive(PrimitiveType type, const VertexTex2 *vertices, in
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_NORMAL_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY); // GL_TEXTURE1
- glClientActiveTexture(GL_TEXTURE0);
- glDisableClientState(GL_TEXTURE_COORD_ARRAY);
+ if (m_multitextureAvailable)
+ {
+ glClientActiveTexture(GL_TEXTURE0);
+ glDisableClientState(GL_TEXTURE_COORD_ARRAY);
+ }
}
void CGLDevice::DrawPrimitive(PrimitiveType type, const VertexCol *vertices, int vertexCount)
@@ -927,29 +961,318 @@ void CGLDevice::DrawPrimitive(PrimitiveType type, const VertexCol *vertices, int
glDisableClientState(GL_COLOR_ARRAY);
}
+unsigned int CGLDevice::CreateStaticBuffer(PrimitiveType primitiveType, const Vertex* vertices, int vertexCount)
+{
+ unsigned int id = 0;
+ if (m_vboAvailable)
+ {
+ id = ++m_lastVboId;
+
+ VboObjectInfo info;
+ info.primitiveType = primitiveType;
+ info.vertexType = VERTEX_TYPE_NORMAL;
+ info.vertexCount = vertexCount;
+ info.bufferId = 0;
+
+ glGenBuffers(1, &info.bufferId);
+ glBindBuffer(GL_ARRAY_BUFFER, info.bufferId);
+ glBufferData(GL_ARRAY_BUFFER, vertexCount * sizeof(Vertex), vertices, GL_STATIC_DRAW);
+ glBindBuffer(GL_ARRAY_BUFFER, 0);
+
+ m_vboObjects[id] = info;
+ }
+ else
+ {
+ id = glGenLists(1);
+
+ glNewList(id, GL_COMPILE);
+
+ DrawPrimitive(primitiveType, vertices, vertexCount);
+
+ glEndList();
+ }
+
+ return id;
+}
+
+unsigned int CGLDevice::CreateStaticBuffer(PrimitiveType primitiveType, const VertexTex2* vertices, int vertexCount)
+{
+ unsigned int id = 0;
+ if (m_vboAvailable)
+ {
+ id = ++m_lastVboId;
+
+ VboObjectInfo info;
+ info.primitiveType = primitiveType;
+ info.vertexType = VERTEX_TYPE_TEX2;
+ info.vertexCount = vertexCount;
+ info.bufferId = 0;
+
+ glGenBuffers(1, &info.bufferId);
+ glBindBuffer(GL_ARRAY_BUFFER, info.bufferId);
+ glBufferData(GL_ARRAY_BUFFER, vertexCount * sizeof(VertexTex2), vertices, GL_STATIC_DRAW);
+ glBindBuffer(GL_ARRAY_BUFFER, 0);
+
+ m_vboObjects[id] = info;
+ }
+ else
+ {
+ id = glGenLists(1);
+
+ glNewList(id, GL_COMPILE);
+
+ DrawPrimitive(primitiveType, vertices, vertexCount);
+
+ glEndList();
+ }
+
+ return id;
+}
+
+unsigned int CGLDevice::CreateStaticBuffer(PrimitiveType primitiveType, const VertexCol* vertices, int vertexCount)
+{
+ unsigned int id = 0;
+ if (m_vboAvailable)
+ {
+ id = ++m_lastVboId;
+
+ VboObjectInfo info;
+ info.primitiveType = primitiveType;
+ info.vertexType = VERTEX_TYPE_COL;
+ info.vertexCount = vertexCount;
+ info.bufferId = 0;
+
+ glGenBuffers(1, &info.bufferId);
+ glBindBuffer(GL_ARRAY_BUFFER, info.bufferId);
+ glBufferData(GL_ARRAY_BUFFER, vertexCount * sizeof(VertexCol), vertices, GL_STATIC_DRAW);
+ glBindBuffer(GL_ARRAY_BUFFER, 0);
+
+ m_vboObjects[id] = info;
+ }
+ else
+ {
+ id = glGenLists(1);
+
+ glNewList(id, GL_COMPILE);
+
+ DrawPrimitive(primitiveType, vertices, vertexCount);
+
+ glEndList();
+ }
+
+ return id;
+}
+
+void CGLDevice::UpdateStaticBuffer(unsigned int bufferId, PrimitiveType primitiveType, const Vertex* vertices, int vertexCount)
+{
+ if (m_vboAvailable)
+ {
+ auto it = m_vboObjects.find(bufferId);
+ if (it == m_vboObjects.end())
+ return;
+
+ VboObjectInfo& info = (*it).second;
+ info.primitiveType = primitiveType;
+ info.vertexType = VERTEX_TYPE_NORMAL;
+ info.vertexCount = vertexCount;
+
+ glBindBuffer(GL_ARRAY_BUFFER, info.bufferId);
+ glBufferData(GL_ARRAY_BUFFER, vertexCount * sizeof(Vertex), vertices, GL_STATIC_DRAW);
+ glBindBuffer(GL_ARRAY_BUFFER, 0);
+ }
+ else
+ {
+ glNewList(bufferId, GL_COMPILE);
+
+ DrawPrimitive(primitiveType, vertices, vertexCount);
+
+ glEndList();
+ }
+}
+
+void CGLDevice::UpdateStaticBuffer(unsigned int bufferId, PrimitiveType primitiveType, const VertexTex2* vertices, int vertexCount)
+{
+ if (m_vboAvailable)
+ {
+ auto it = m_vboObjects.find(bufferId);
+ if (it == m_vboObjects.end())
+ return;
+
+ VboObjectInfo& info = (*it).second;
+ info.primitiveType = primitiveType;
+ info.vertexType = VERTEX_TYPE_TEX2;
+ info.vertexCount = vertexCount;
+
+ glBindBuffer(GL_ARRAY_BUFFER, info.bufferId);
+ glBufferData(GL_ARRAY_BUFFER, vertexCount * sizeof(VertexTex2), vertices, GL_STATIC_DRAW);
+ glBindBuffer(GL_ARRAY_BUFFER, 0);
+ }
+ else
+ {
+ glNewList(bufferId, GL_COMPILE);
+
+ DrawPrimitive(primitiveType, vertices, vertexCount);
+
+ glEndList();
+ }
+}
+
+void CGLDevice::UpdateStaticBuffer(unsigned int bufferId, PrimitiveType primitiveType, const VertexCol* vertices, int vertexCount)
+{
+ if (m_vboAvailable)
+ {
+ auto it = m_vboObjects.find(bufferId);
+ if (it == m_vboObjects.end())
+ return;
+
+ VboObjectInfo& info = (*it).second;
+ info.primitiveType = primitiveType;
+ info.vertexType = VERTEX_TYPE_COL;
+ info.vertexCount = vertexCount;
+
+ glBindBuffer(GL_ARRAY_BUFFER, info.bufferId);
+ glBufferData(GL_ARRAY_BUFFER, vertexCount * sizeof(VertexCol), vertices, GL_STATIC_DRAW);
+ glBindBuffer(GL_ARRAY_BUFFER, 0);
+ }
+ else
+ {
+ glNewList(bufferId, GL_COMPILE);
+
+ DrawPrimitive(primitiveType, vertices, vertexCount);
+
+ glEndList();
+ }
+}
+
+void CGLDevice::DrawStaticBuffer(unsigned int bufferId)
+{
+ if (m_vboAvailable)
+ {
+ auto it = m_vboObjects.find(bufferId);
+ if (it == m_vboObjects.end())
+ return;
+
+ glEnable(GL_VERTEX_ARRAY);
+ glBindBuffer(GL_ARRAY_BUFFER, (*it).second.bufferId);
+
+ if ((*it).second.vertexType == VERTEX_TYPE_NORMAL)
+ {
+ glEnableClientState(GL_VERTEX_ARRAY);
+ glVertexPointer(3, GL_FLOAT, sizeof(Vertex), static_cast<char*>(nullptr) + offsetof(Vertex, coord));
+
+ glEnableClientState(GL_NORMAL_ARRAY);
+ glNormalPointer(GL_FLOAT, sizeof(Vertex), static_cast<char*>(nullptr) + offsetof(Vertex, normal));
+
+ if (m_multitextureAvailable)
+ glClientActiveTexture(GL_TEXTURE0);
+
+ glEnableClientState(GL_TEXTURE_COORD_ARRAY);
+ glTexCoordPointer(2, GL_FLOAT, sizeof(Vertex), static_cast<char*>(nullptr) + offsetof(Vertex, texCoord));
+ }
+ else if ((*it).second.vertexType == VERTEX_TYPE_TEX2)
+ {
+ glEnableClientState(GL_VERTEX_ARRAY);
+ glVertexPointer(3, GL_FLOAT, sizeof(VertexTex2), static_cast<char*>(nullptr) + offsetof(VertexTex2, coord));
+
+ glEnableClientState(GL_NORMAL_ARRAY);
+ glNormalPointer(GL_FLOAT, sizeof(VertexTex2), static_cast<char*>(nullptr) + offsetof(VertexTex2, normal));
+
+ if (m_multitextureAvailable)
+ glClientActiveTexture(GL_TEXTURE0);
+
+ glEnableClientState(GL_TEXTURE_COORD_ARRAY);
+ glTexCoordPointer(2, GL_FLOAT, sizeof(VertexTex2), static_cast<char*>(nullptr) + offsetof(VertexTex2, texCoord));
+
+ if (m_multitextureAvailable)
+ {
+ glClientActiveTexture(GL_TEXTURE1);
+ glEnableClientState(GL_TEXTURE_COORD_ARRAY);
+ glTexCoordPointer(2, GL_FLOAT, sizeof(VertexTex2), static_cast<char*>(nullptr) + offsetof(VertexTex2, texCoord2));
+ }
+ }
+ else if ((*it).second.vertexType == VERTEX_TYPE_COL)
+ {
+ glEnableClientState(GL_VERTEX_ARRAY);
+ glVertexPointer(3, GL_FLOAT, sizeof(VertexCol), static_cast<char*>(nullptr) + offsetof(VertexCol, coord));
+
+ glEnableClientState(GL_COLOR_ARRAY);
+ glColorPointer(4, GL_FLOAT, sizeof(VertexCol), static_cast<char*>(nullptr) + offsetof(VertexCol, color));
+ }
+
+ GLenum mode = TranslateGfxPrimitive((*it).second.primitiveType);
+ glDrawArrays(mode, 0, (*it).second.vertexCount);
+
+ if ((*it).second.vertexType == VERTEX_TYPE_NORMAL)
+ {
+ glDisableClientState(GL_VERTEX_ARRAY);
+ glDisableClientState(GL_NORMAL_ARRAY);
+ glDisableClientState(GL_TEXTURE_COORD_ARRAY); // GL_TEXTURE0
+ }
+ else if ((*it).second.vertexType == VERTEX_TYPE_TEX2)
+ {
+ glDisableClientState(GL_VERTEX_ARRAY);
+ glDisableClientState(GL_NORMAL_ARRAY);
+ glDisableClientState(GL_TEXTURE_COORD_ARRAY); // GL_TEXTURE1
+ if (m_multitextureAvailable)
+ {
+ glClientActiveTexture(GL_TEXTURE0);
+ glDisableClientState(GL_TEXTURE_COORD_ARRAY);
+ }
+ }
+ else if ((*it).second.vertexType == VERTEX_TYPE_COL)
+ {
+ glDisableClientState(GL_VERTEX_ARRAY);
+ glDisableClientState(GL_COLOR_ARRAY);
+ }
+
+ glBindBuffer(GL_ARRAY_BUFFER, 0);
+ glDisable(GL_VERTEX_ARRAY);
+ }
+ else
+ {
+ glCallList(bufferId);
+ }
+}
+
+void CGLDevice::DestroyStaticBuffer(unsigned int bufferId)
+{
+ if (m_vboAvailable)
+ {
+ auto it = m_vboObjects.find(bufferId);
+ if (it == m_vboObjects.end())
+ return;
+
+ glDeleteBuffers(1, &(*it).second.bufferId);
+
+ m_vboObjects.erase(it);
+ }
+ else
+ {
+ glDeleteLists(bufferId, 1);
+ }
+}
+
bool InPlane(Math::Vector normal, float originPlane, Math::Vector center, float radius)
{
- float distance = (originPlane + Math::DotProduct(normal, center)) / normal.Length();
+ float distance = originPlane + Math::DotProduct(normal, center);
if (distance < -radius)
- return true;
+ return false;
- return false;
+ return true;
}
-/*
- The implementation of ComputeSphereVisibility is taken from libwine's device.c
- Copyright of the WINE team, licensed under GNU LGPL v 2.1
- */
+/* Based on libwine's implementation */
-// TODO: testing
int CGLDevice::ComputeSphereVisibility(const Math::Vector &center, float radius)
{
Math::Matrix m;
- m.LoadIdentity();
- m = Math::MultiplyMatrices(m, m_worldMat);
- m = Math::MultiplyMatrices(m, m_viewMat);
- m = Math::MultiplyMatrices(m, m_projectionMat);
+ m = Math::MultiplyMatrices(m_worldMat, m);
+ m = Math::MultiplyMatrices(m_viewMat, m);
+ Math::Matrix sc;
+ Math::LoadScaleMatrix(sc, Math::Vector(1.0f, 1.0f, -1.0f));
+ m = Math::MultiplyMatrices(sc, m);
+ m = Math::MultiplyMatrices(m_projectionMat, m);
Math::Vector vec[6];
float originPlane[6];
@@ -958,52 +1281,64 @@ int CGLDevice::ComputeSphereVisibility(const Math::Vector &center, float radius)
vec[0].x = m.Get(4, 1) + m.Get(1, 1);
vec[0].y = m.Get(4, 2) + m.Get(1, 2);
vec[0].z = m.Get(4, 3) + m.Get(1, 3);
- originPlane[0] = m.Get(4, 4) + m.Get(1, 4);
+ float l1 = vec[0].Length();
+ vec[0].Normalize();
+ originPlane[0] = (m.Get(4, 4) + m.Get(1, 4)) / l1;
// Right plane
vec[1].x = m.Get(4, 1) - m.Get(1, 1);
vec[1].y = m.Get(4, 2) - m.Get(1, 2);
vec[1].z = m.Get(4, 3) - m.Get(1, 3);
- originPlane[1] = m.Get(4, 4) - m.Get(1, 4);
-
- // Top plane
- vec[2].x = m.Get(4, 1) - m.Get(2, 1);
- vec[2].y = m.Get(4, 2) - m.Get(2, 2);
- vec[2].z = m.Get(4, 3) - m.Get(2, 3);
- originPlane[2] = m.Get(4, 4) - m.Get(2, 4);
+ float l2 = vec[1].Length();
+ vec[1].Normalize();
+ originPlane[1] = (m.Get(4, 4) - m.Get(1, 4)) / l2;
// Bottom plane
- vec[3].x = m.Get(4, 1) + m.Get(2, 1);
- vec[3].y = m.Get(4, 2) + m.Get(2, 2);
- vec[3].z = m.Get(4, 3) + m.Get(2, 3);
- originPlane[3] = m.Get(4, 4) + m.Get(2, 4);
+ vec[2].x = m.Get(4, 1) + m.Get(2, 1);
+ vec[2].y = m.Get(4, 2) + m.Get(2, 2);
+ vec[2].z = m.Get(4, 3) + m.Get(2, 3);
+ float l3 = vec[2].Length();
+ vec[2].Normalize();
+ originPlane[2] = (m.Get(4, 4) + m.Get(2, 4)) / l3;
+
+ // Top plane
+ vec[3].x = m.Get(4, 1) - m.Get(2, 1);
+ vec[3].y = m.Get(4, 2) - m.Get(2, 2);
+ vec[3].z = m.Get(4, 3) - m.Get(2, 3);
+ float l4 = vec[3].Length();
+ vec[3].Normalize();
+ originPlane[3] = (m.Get(4, 4) - m.Get(2, 4)) / l4;
// Front plane
- vec[4].x = m.Get(3, 1);
- vec[4].y = m.Get(3, 2);
- vec[4].z = m.Get(3, 3);
- originPlane[4] = m.Get(3, 4);
+ vec[4].x = m.Get(4, 1) + m.Get(3, 1);
+ vec[4].y = m.Get(4, 2) + m.Get(3, 2);
+ vec[4].z = m.Get(4, 3) + m.Get(3, 3);
+ float l5 = vec[4].Length();
+ vec[4].Normalize();
+ originPlane[4] = (m.Get(4, 4) + m.Get(3, 4)) / l5;
// Back plane
vec[5].x = m.Get(4, 1) - m.Get(3, 1);
vec[5].y = m.Get(4, 2) - m.Get(3, 2);
vec[5].z = m.Get(4, 3) - m.Get(3, 3);
- originPlane[5] = m.Get(4, 4) - m.Get(3, 4);
+ float l6 = vec[5].Length();
+ vec[5].Normalize();
+ originPlane[5] = (m.Get(4, 4) - m.Get(3, 4)) / l6;
int result = 0;
if (InPlane(vec[0], originPlane[0], center, radius))
- result |= INTERSECT_PLANE_LEFT;
+ result |= FRUSTUM_PLANE_LEFT;
if (InPlane(vec[1], originPlane[1], center, radius))
- result |= INTERSECT_PLANE_RIGHT;
+ result |= FRUSTUM_PLANE_RIGHT;
if (InPlane(vec[2], originPlane[2], center, radius))
- result |= INTERSECT_PLANE_TOP;
+ result |= FRUSTUM_PLANE_BOTTOM;
if (InPlane(vec[3], originPlane[3], center, radius))
- result |= INTERSECT_PLANE_BOTTOM;
+ result |= FRUSTUM_PLANE_TOP;
if (InPlane(vec[4], originPlane[4], center, radius))
- result |= INTERSECT_PLANE_FRONT;
+ result |= FRUSTUM_PLANE_FRONT;
if (InPlane(vec[5], originPlane[5], center, radius))
- result |= INTERSECT_PLANE_BACK;
+ result |= FRUSTUM_PLANE_BACK;
return result;
}
@@ -1042,7 +1377,6 @@ void CGLDevice::SetRenderState(RenderState state, bool enabled)
case RENDER_STATE_DEPTH_TEST: flag = GL_DEPTH_TEST; break;
case RENDER_STATE_ALPHA_TEST: flag = GL_ALPHA_TEST; break;
case RENDER_STATE_CULLING: flag = GL_CULL_FACE; break;
- case RENDER_STATE_DITHERING: flag = GL_DITHER; break;
default: assert(false); break;
}
@@ -1067,7 +1401,6 @@ bool CGLDevice::GetRenderState(RenderState state)
case RENDER_STATE_DEPTH_TEST: flag = GL_DEPTH_TEST; break;
case RENDER_STATE_ALPHA_TEST: flag = GL_ALPHA_TEST; break;
case RENDER_STATE_CULLING: flag = GL_CULL_FACE; break;
- case RENDER_STATE_DITHERING: flag = GL_DITHER; break;
default: assert(false); break;
}
diff --git a/src/graphics/opengl/gldevice.h b/src/graphics/opengl/gldevice.h
index 87c1247..7137671 100644
--- a/src/graphics/opengl/gldevice.h
+++ b/src/graphics/opengl/gldevice.h
@@ -27,6 +27,7 @@
#include <string>
#include <vector>
#include <set>
+#include <map>
// Graphics module namespace
@@ -84,6 +85,9 @@ public:
void ConfigChanged(const GLDeviceConfig &newConfig);
+ void SetUseVbo(bool useVbo);
+ bool GetUseVbo();
+
virtual void BeginScene();
virtual void EndScene();
@@ -107,7 +111,7 @@ public:
virtual void DestroyTexture(const Texture &texture);
virtual void DestroyAllTextures();
- virtual int GetMaxTextureCount();
+ virtual int GetMaxTextureStageCount();
virtual void SetTexture(int index, const Texture &texture);
virtual void SetTexture(int index, unsigned int textureId);
virtual Texture GetTexture(int index);
@@ -119,14 +123,21 @@ public:
virtual void SetTextureStageWrap(int index, Gfx::TexWrapMode wrapS, Gfx::TexWrapMode wrapT);
- //! Renders primitive composed of vertices with single texture
virtual void DrawPrimitive(PrimitiveType type, const Vertex *vertices , int vertexCount,
Color color = Color(1.0f, 1.0f, 1.0f, 1.0f));
- //! Renders primitive composed of vertices with multitexturing (2 textures)
virtual void DrawPrimitive(PrimitiveType type, const VertexTex2 *vertices, int vertexCount,
Color color = Color(1.0f, 1.0f, 1.0f, 1.0f));
virtual void DrawPrimitive(PrimitiveType type, const VertexCol *vertices , int vertexCount);
+ virtual unsigned int CreateStaticBuffer(PrimitiveType primitiveType, const Vertex* vertices, int vertexCount);
+ virtual unsigned int CreateStaticBuffer(PrimitiveType primitiveType, const VertexTex2* vertices, int vertexCount);
+ virtual unsigned int CreateStaticBuffer(PrimitiveType primitiveType, const VertexCol* vertices, int vertexCount);
+ virtual void UpdateStaticBuffer(unsigned int bufferId, PrimitiveType primitiveType, const Vertex* vertices, int vertexCount);
+ virtual void UpdateStaticBuffer(unsigned int bufferId, PrimitiveType primitiveType, const VertexTex2* vertices, int vertexCount);
+ virtual void UpdateStaticBuffer(unsigned int bufferId, PrimitiveType primitiveType, const VertexCol* vertices, int vertexCount);
+ virtual void DrawStaticBuffer(unsigned int bufferId);
+ virtual void DestroyStaticBuffer(unsigned int bufferId);
+
virtual int ComputeSphereVisibility(const Math::Vector &center, float radius);
virtual void SetRenderState(RenderState state, bool enabled);
@@ -200,6 +211,32 @@ private:
//! Set of all created textures
std::set<Texture> m_allTextures;
+
+ //! Type of vertex structure
+ enum VertexType
+ {
+ VERTEX_TYPE_NORMAL,
+ VERTEX_TYPE_TEX2,
+ VERTEX_TYPE_COL,
+ };
+
+ //! Info about static VBO buffers
+ struct VboObjectInfo
+ {
+ PrimitiveType primitiveType;
+ unsigned int bufferId;
+ VertexType vertexType;
+ int vertexCount;
+ };
+
+ //! Whether to use multitexturing
+ bool m_multitextureAvailable;
+ //! Whether to use VBOs or display lists
+ bool m_vboAvailable;
+ //! Map of saved VBO objects
+ std::map<unsigned int, VboObjectInfo> m_vboObjects;
+ //! Last ID of VBO object
+ unsigned int m_lastVboId;
};
diff --git a/src/graphics/opengl/test/CMakeLists.txt b/src/graphics/opengl/test/CMakeLists.txt
index 154fec8..79e0ba5 100644
--- a/src/graphics/opengl/test/CMakeLists.txt
+++ b/src/graphics/opengl/test/CMakeLists.txt
@@ -8,7 +8,6 @@ find_package(PNG REQUIRED)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE debug)
endif(NOT CMAKE_BUILD_TYPE)
-set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wold-style-cast -std=gnu++0x")
set(CMAKE_CXX_FLAGS_DEBUG "-g -O0")
set(ADD_LIBS "")
diff --git a/src/graphics/opengl/test/light_test.cpp b/src/graphics/opengl/test/light_test.cpp
index 6ff3b1c..b19ba4b 100644
--- a/src/graphics/opengl/test/light_test.cpp
+++ b/src/graphics/opengl/test/light_test.cpp
@@ -51,7 +51,7 @@ void Render(Gfx::CGLDevice *device)
device->SetRenderState(Gfx::RENDER_STATE_CULLING, false); // Double-sided drawing
Math::Matrix persp;
- Math::LoadProjectionMatrix(persp, Math::PI / 4.0f, (800.0f) / (600.0f), 0.1f, 100.0f);
+ Math::LoadProjectionMatrix(persp, Math::PI / 4.0f, (800.0f) / (600.0f), 0.1f, 50.0f);
device->SetTransform(Gfx::TRANSFORM_PROJECTION, persp);
@@ -121,6 +121,31 @@ void Render(Gfx::CGLDevice *device)
Math::LoadTranslationMatrix(worldMat, Math::Vector(-40.0f, 2.0f, -40.0f));
device->SetTransform(Gfx::TRANSFORM_WORLD, worldMat);
+ int planes = device->ComputeSphereVisibility(Math::Vector(0.0f, 0.0f, 0.0f), 1.0f);
+ printf("Planes:");
+ if (planes == 0)
+ printf(" (none)");
+
+ if (planes & Gfx::FRUSTUM_PLANE_LEFT)
+ printf(" LEFT");
+
+ if (planes & Gfx::FRUSTUM_PLANE_RIGHT)
+ printf(" RIGHT");
+
+ if (planes & Gfx::FRUSTUM_PLANE_BOTTOM)
+ printf(" BOTTOM");
+
+ if (planes & Gfx::FRUSTUM_PLANE_TOP)
+ printf(" TOP");
+
+ if (planes & Gfx::FRUSTUM_PLANE_FRONT)
+ printf(" FRONT");
+
+ if (planes & Gfx::FRUSTUM_PLANE_BACK)
+ printf(" BACK");
+
+ printf("\n");
+
device->DrawPrimitive(Gfx::PRIMITIVE_TRIANGLE_STRIP, quad, 4);
for (int i = 0; i < 6; ++i)
diff --git a/src/graphics/opengl/test/texture_test.cpp b/src/graphics/opengl/test/texture_test.cpp
index 534a5c0..d771927 100644
--- a/src/graphics/opengl/test/texture_test.cpp
+++ b/src/graphics/opengl/test/texture_test.cpp
@@ -13,7 +13,6 @@ void Init(Gfx::CGLDevice *device)
device->SetShadeModel(Gfx::SHADE_SMOOTH);
device->SetRenderState(Gfx::RENDER_STATE_DEPTH_TEST, false);
- device->SetRenderState(Gfx::RENDER_STATE_TEXTURING, true);
device->SetTextureEnabled(0, true);
device->SetTextureEnabled(1, true);
diff --git a/src/math/intpoint.h b/src/math/intpoint.h
index ebd9c5e..010b0fb 100644
--- a/src/math/intpoint.h
+++ b/src/math/intpoint.h
@@ -21,6 +21,7 @@
#pragma once
+#include <cmath>
// Math module namespace
namespace Math {
@@ -49,6 +50,11 @@ struct IntPoint
{
return !operator==(p);
}
+
+ inline float Length() const
+ {
+ return sqrtf(x*x + y*y);
+ }
};
diff --git a/src/math/test/CMakeLists.txt b/src/math/test/CMakeLists.txt
index dae4018..e31260c 100644
--- a/src/math/test/CMakeLists.txt
+++ b/src/math/test/CMakeLists.txt
@@ -3,7 +3,6 @@ cmake_minimum_required(VERSION 2.8)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE debug)
endif(NOT CMAKE_BUILD_TYPE)
-set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wold-style-cast -std=gnu++0x")
set(CMAKE_CXX_FLAGS_DEBUG "-g -O0")
include_directories(
diff --git a/src/object/motion/motionant.cpp b/src/object/motion/motionant.cpp
index 07ee6b8..db8ff37 100644
--- a/src/object/motion/motionant.cpp
+++ b/src/object/motion/motionant.cpp
@@ -19,7 +19,7 @@
#include "app/app.h"
-#include "graphics/engine/modelfile.h"
+#include "graphics/engine/modelmanager.h"
#include "graphics/engine/particle.h"
#include "physics/physics.h"
@@ -69,12 +69,8 @@ void CMotionAnt::DeleteObject(bool bAll)
bool CMotionAnt::Create(Math::Vector pos, float angle, ObjectType type,
float power)
{
- Gfx::CModelFile* pModFile;
- int rank;
-
-// if ( m_engine->GetRestCreate() < 3+18 ) return false;
-
- pModFile = new Gfx::CModelFile(m_iMan);
+ Gfx::CModelManager* modelManager = Gfx::CModelManager::GetInstancePointer();
+ int rank;
m_object->SetType(type);
@@ -82,10 +78,7 @@ bool CMotionAnt::Create(Math::Vector pos, float angle, ObjectType type,
rank = m_engine->CreateObject();
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_VEHICULE); // this is a moving object
m_object->SetObjectRank(0, rank);
-
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "ant1.mod"));
- pModFile->CreateEngineObject(rank);
-
+ modelManager->AddModelReference("ant1.mod", false, rank);
m_object->SetPosition(0, pos);
m_object->SetAngleY(0, angle);
@@ -96,29 +89,26 @@ bool CMotionAnt::Create(Math::Vector pos, float angle, ObjectType type,
// Creates the head.
rank = m_engine->CreateObject();
- m_engine->SetObjectType(rank,Gfx::ENG_OBJTYPE_DESCENDANT);
+ m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(1, rank);
m_object->SetObjectParent(1, 0);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "ant2.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("ant2.mod", false, rank);
m_object->SetPosition(1, Math::Vector(2.0f, 0.0f, 0.0f));
// Creates the tail.
rank = m_engine->CreateObject();
- m_engine->SetObjectType(rank,Gfx::ENG_OBJTYPE_DESCENDANT);
+ m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(2, rank);
m_object->SetObjectParent(2, 0);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "ant3.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("ant3.mod", false, rank);
m_object->SetPosition(2, Math::Vector(-1.0f, 0.0f, 0.0f));
// Creates a right-back thigh.
rank = m_engine->CreateObject();
- m_engine->SetObjectType(rank,Gfx::ENG_OBJTYPE_DESCENDANT);
+ m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(3, rank);
m_object->SetObjectParent(3, 0);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "ant4.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("ant4.mod", false, rank);
m_object->SetPosition(3, Math::Vector(-0.4f, -0.1f, -0.3f));
// Creates a right-back leg.
@@ -126,161 +116,135 @@ bool CMotionAnt::Create(Math::Vector pos, float angle, ObjectType type,
m_engine->SetObjectType(rank,Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(4, rank);
m_object->SetObjectParent(4, 3);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "ant5.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("ant5.mod", false, rank);
m_object->SetPosition(4, Math::Vector(0.0f, 0.0f, -1.0f));
// Creates a right-back foot.
rank = m_engine->CreateObject();
- m_engine->SetObjectType(rank,Gfx::ENG_OBJTYPE_DESCENDANT);
+ m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(5, rank);
m_object->SetObjectParent(5, 4);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "ant6.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("ant6.mod", false, rank);
m_object->SetPosition(5, Math::Vector(0.0f, 0.0f, -2.0f));
// Creates two middle-right thighs.
rank = m_engine->CreateObject();
- m_engine->SetObjectType(rank,Gfx::ENG_OBJTYPE_DESCENDANT);
+ m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(6, rank);
m_object->SetObjectParent(6, 0);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "ant4.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("ant4.mod", false, rank);
m_object->SetPosition(6, Math::Vector(0.1f, -0.1f, -0.4f));
// Creates two middle-right legs.
rank = m_engine->CreateObject();
- m_engine->SetObjectType(rank,Gfx::ENG_OBJTYPE_DESCENDANT);
+ m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(7, rank);
m_object->SetObjectParent(7, 6);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "ant5.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("ant5.mod", false, rank);
m_object->SetPosition(7, Math::Vector(0.0f, 0.0f, -1.0f));
// Creates two middle-right foots.
rank = m_engine->CreateObject();
- m_engine->SetObjectType(rank,Gfx::ENG_OBJTYPE_DESCENDANT);
+ m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(8, rank);
m_object->SetObjectParent(8, 7);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "ant6.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("ant6.mod", false, rank);
m_object->SetPosition(8, Math::Vector(0.0f, 0.0f, -2.0f));
// Creates the right front thigh.
rank = m_engine->CreateObject();
- m_engine->SetObjectType(rank,Gfx::ENG_OBJTYPE_DESCENDANT);
+ m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(9, rank);
m_object->SetObjectParent(9, 0);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "ant4.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("ant4.mod", false, rank);
m_object->SetPosition(9, Math::Vector(1.4f, -0.1f, -0.6f));
// Creates the right front leg.
rank = m_engine->CreateObject();
- m_engine->SetObjectType(rank,Gfx::ENG_OBJTYPE_DESCENDANT);
+ m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(10, rank);
m_object->SetObjectParent(10, 9);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "ant5.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("ant5.mod", false, rank);
m_object->SetPosition(10, Math::Vector(0.0f, 0.0f, -1.0f));
// Creates the right front foot.
rank = m_engine->CreateObject();
- m_engine->SetObjectType(rank,Gfx::ENG_OBJTYPE_DESCENDANT);
+ m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(11, rank);
m_object->SetObjectParent(11, 10);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "ant6.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("ant6.mod", false, rank);
m_object->SetPosition(11, Math::Vector(0.0f, 0.0f, -2.0f));
// Creates a left-back thigh.
rank = m_engine->CreateObject();
- m_engine->SetObjectType(rank,Gfx::ENG_OBJTYPE_DESCENDANT);
+ m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(12, rank);
m_object->SetObjectParent(12, 0);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "ant4.mod"));
- pModFile->Mirror();
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("ant4.mod", true, rank);
m_object->SetPosition(12, Math::Vector(-0.4f, -0.1f, 0.3f));
// Creates a left-back leg.
rank = m_engine->CreateObject();
- m_engine->SetObjectType(rank,Gfx::ENG_OBJTYPE_DESCENDANT);
+ m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(13, rank);
m_object->SetObjectParent(13, 12);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "ant5.mod"));
- pModFile->Mirror();
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("ant5.mod", true, rank);
m_object->SetPosition(13, Math::Vector(0.0f, 0.0f, 1.0f));
// Creates a left-back foot.
rank = m_engine->CreateObject();
- m_engine->SetObjectType(rank,Gfx::ENG_OBJTYPE_DESCENDANT);
+ m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(14, rank);
m_object->SetObjectParent(14, 13);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "ant6.mod"));
- pModFile->Mirror();
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("ant6.mod", true, rank);
m_object->SetPosition(14, Math::Vector(0.0f, 0.0f, 2.0f));
// Creates two middle-left thighs.
rank = m_engine->CreateObject();
- m_engine->SetObjectType(rank,Gfx::ENG_OBJTYPE_DESCENDANT);
+ m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(15, rank);
m_object->SetObjectParent(15, 0);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "ant4.mod"));
- pModFile->Mirror();
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("ant4.mod", true, rank);
m_object->SetPosition(15, Math::Vector(0.1f, -0.1f, 0.4f));
// Creates two middle-left legs.
rank = m_engine->CreateObject();
- m_engine->SetObjectType(rank,Gfx::ENG_OBJTYPE_DESCENDANT);
+ m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(16, rank);
m_object->SetObjectParent(16, 15);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "ant5.mod"));
- pModFile->Mirror();
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("ant5.mod", true, rank);
m_object->SetPosition(16, Math::Vector(0.0f, 0.0f, 1.0f));
// Creates two middle-left foot.
rank = m_engine->CreateObject();
- m_engine->SetObjectType(rank,Gfx::ENG_OBJTYPE_DESCENDANT);
+ m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(17, rank);
m_object->SetObjectParent(17, 16);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "ant6.mod"));
- pModFile->Mirror();
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("ant6.mod", true, rank);
m_object->SetPosition(17, Math::Vector(0.0f, 0.0f, 2.0f));
// Creates the left front thigh.
rank = m_engine->CreateObject();
- m_engine->SetObjectType(rank,Gfx::ENG_OBJTYPE_DESCENDANT);
+ m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(18, rank);
m_object->SetObjectParent(18, 0);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "ant4.mod"));
- pModFile->Mirror();
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("ant4.mod", true, rank);
m_object->SetPosition(18, Math::Vector(1.4f, -0.1f, 0.6f));
// Creates the left front leg.
rank = m_engine->CreateObject();
- m_engine->SetObjectType(rank,Gfx::ENG_OBJTYPE_DESCENDANT);
+ m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(19, rank);
m_object->SetObjectParent(19, 18);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "ant5.mod"));
- pModFile->Mirror();
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("ant5.mod", true, rank);
m_object->SetPosition(19, Math::Vector(0.0f, 0.0f, 1.0f));
// Creates the left front foot.
rank = m_engine->CreateObject();
- m_engine->SetObjectType(rank,Gfx::ENG_OBJTYPE_DESCENDANT);
+ m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(20, rank);
m_object->SetObjectParent(20, 19);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "ant6.mod"));
- pModFile->Mirror();
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("ant6.mod", true, rank);
m_object->SetPosition(20, Math::Vector(0.0f, 0.0f, 2.0f));
m_object->CreateShadowCircle(4.0f, 0.5f);
@@ -293,7 +257,6 @@ bool CMotionAnt::Create(Math::Vector pos, float angle, ObjectType type,
m_engine->LoadAllTextures();
- delete pModFile;
return true;
}
diff --git a/src/object/motion/motionbee.cpp b/src/object/motion/motionbee.cpp
index a3421b8..111339d 100644
--- a/src/object/motion/motionbee.cpp
+++ b/src/object/motion/motionbee.cpp
@@ -19,7 +19,7 @@
#include "app/app.h"
-#include "graphics/engine/modelfile.h"
+#include "graphics/engine/modelmanager.h"
#include "physics/physics.h"
@@ -67,12 +67,8 @@ void CMotionBee::DeleteObject(bool bAll)
bool CMotionBee::Create(Math::Vector pos, float angle, ObjectType type,
float power)
{
- Gfx::CModelFile* pModFile;
- int rank;
-
-// if ( m_engine->GetRestCreate() < 3+18+2 ) return false;
-
- pModFile = new Gfx::CModelFile(m_iMan);
+ Gfx::CModelManager* modelManager = Gfx::CModelManager::GetInstancePointer();
+ int rank;
m_object->SetType(type);
@@ -80,10 +76,7 @@ bool CMotionBee::Create(Math::Vector pos, float angle, ObjectType type,
rank = m_engine->CreateObject();
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_VEHICULE); // this is a moving object
m_object->SetObjectRank(0, rank);
-
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "bee1.mod"));
- pModFile->CreateEngineObject(rank);
-
+ modelManager->AddModelReference("bee1.mod", false, rank);
m_object->SetPosition(0, pos);
m_object->SetAngleY(0, angle);
@@ -97,8 +90,7 @@ bool CMotionBee::Create(Math::Vector pos, float angle, ObjectType type,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(1, rank);
m_object->SetObjectParent(1, 0);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "bee2.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("bee2.mod", false, rank);
m_object->SetPosition(1, Math::Vector(1.6f, 0.3f, 0.0f));
// Creates the tail.
@@ -106,8 +98,7 @@ bool CMotionBee::Create(Math::Vector pos, float angle, ObjectType type,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(2, rank);
m_object->SetObjectParent(2, 0);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "bee3.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("bee3.mod", false, rank);
m_object->SetPosition(2, Math::Vector(-0.8f, 0.0f, 0.0f));
// Creates a right-back thigh.
@@ -115,8 +106,7 @@ bool CMotionBee::Create(Math::Vector pos, float angle, ObjectType type,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(3, rank);
m_object->SetObjectParent(3, 0);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "ant4.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("ant4.mod", false, rank);
m_object->SetPosition(3, Math::Vector(-0.3f, -0.1f, -0.2f));
// Creates a right-back leg.
@@ -124,8 +114,7 @@ bool CMotionBee::Create(Math::Vector pos, float angle, ObjectType type,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(4, rank);
m_object->SetObjectParent(4, 3);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "ant5.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("ant5.mod", false, rank);
m_object->SetPosition(4, Math::Vector(0.0f, 0.0f, -1.0f));
// Creates a right-back foot.
@@ -133,8 +122,7 @@ bool CMotionBee::Create(Math::Vector pos, float angle, ObjectType type,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(5, rank);
m_object->SetObjectParent(5, 4);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "ant6.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("ant6.mod", false, rank);
m_object->SetPosition(5, Math::Vector(0.0f, 0.0f, -2.0f));
// Creates two middle-right thighs.
@@ -142,8 +130,7 @@ bool CMotionBee::Create(Math::Vector pos, float angle, ObjectType type,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(6, rank);
m_object->SetObjectParent(6, 0);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "ant4.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("ant4.mod", false, rank);
m_object->SetPosition(6, Math::Vector(0.3f, -0.1f, -0.4f));
// Creates two middle-right legs.
@@ -151,8 +138,7 @@ bool CMotionBee::Create(Math::Vector pos, float angle, ObjectType type,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(7, rank);
m_object->SetObjectParent(7, 6);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "ant5.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("ant5.mod", false, rank);
m_object->SetPosition(7, Math::Vector(0.0f, 0.0f, -1.0f));
// Creates two middle-right feet.
@@ -160,8 +146,7 @@ bool CMotionBee::Create(Math::Vector pos, float angle, ObjectType type,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(8, rank);
m_object->SetObjectParent(8, 7);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "ant6.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("ant6.mod", false, rank);
m_object->SetPosition(8, Math::Vector(0.0f, 0.0f, -2.0f));
// Creates the right front thigh.
@@ -169,8 +154,7 @@ bool CMotionBee::Create(Math::Vector pos, float angle, ObjectType type,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(9, rank);
m_object->SetObjectParent(9, 0);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "ant4.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("ant4.mod", false, rank);
m_object->SetPosition(9, Math::Vector(1.0f, -0.1f, -0.7f));
// Creates the right front leg.
@@ -178,8 +162,7 @@ bool CMotionBee::Create(Math::Vector pos, float angle, ObjectType type,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(10, rank);
m_object->SetObjectParent(10, 9);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "ant5.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("ant5.mod", false, rank);
m_object->SetPosition(10, Math::Vector(0.0f, 0.0f, -1.0f));
// Creates the right front foot.
@@ -187,8 +170,7 @@ bool CMotionBee::Create(Math::Vector pos, float angle, ObjectType type,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(11, rank);
m_object->SetObjectParent(11, 10);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "ant6.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("ant6.mod", false, rank);
m_object->SetPosition(11, Math::Vector(0.0f, 0.0f, -2.0f));
// Creates a left-back thigh.
@@ -196,8 +178,7 @@ bool CMotionBee::Create(Math::Vector pos, float angle, ObjectType type,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(12, rank);
m_object->SetObjectParent(12, 0);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "ant4.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("ant4.mod", false, rank);
m_object->SetPosition(12, Math::Vector(-0.3f, -0.1f, 0.2f));
m_object->SetAngleY(12, Math::PI);
@@ -206,8 +187,7 @@ bool CMotionBee::Create(Math::Vector pos, float angle, ObjectType type,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(13, rank);
m_object->SetObjectParent(13, 12);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "ant5.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("ant5.mod", false, rank);
m_object->SetPosition(13, Math::Vector(0.0f, 0.0f, -1.0f));
// Creates a left-back foot.
@@ -215,8 +195,7 @@ bool CMotionBee::Create(Math::Vector pos, float angle, ObjectType type,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(14, rank);
m_object->SetObjectParent(14, 13);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "ant6.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("ant6.mod", false, rank);
m_object->SetPosition(14, Math::Vector(0.0f, 0.0f, -2.0f));
// Creates two middle-left thigh.
@@ -224,8 +203,7 @@ bool CMotionBee::Create(Math::Vector pos, float angle, ObjectType type,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(15, rank);
m_object->SetObjectParent(15, 0);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "ant4.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("ant4.mod", false, rank);
m_object->SetPosition(15, Math::Vector(0.3f, -0.1f, 0.4f));
m_object->SetAngleY(15, Math::PI);
@@ -234,8 +212,7 @@ bool CMotionBee::Create(Math::Vector pos, float angle, ObjectType type,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(16, rank);
m_object->SetObjectParent(16, 15);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "ant5.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("ant5.mod", false, rank);
m_object->SetPosition(16, Math::Vector(0.0f, 0.0f, -1.0f));
// Creates two middle-left feet.
@@ -243,8 +220,7 @@ bool CMotionBee::Create(Math::Vector pos, float angle, ObjectType type,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(17, rank);
m_object->SetObjectParent(17, 16);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "ant6.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("ant6.mod", false, rank);
m_object->SetPosition(17, Math::Vector(0.0f, 0.0f, -2.0f));
// Creates front-left thigh.
@@ -252,8 +228,7 @@ bool CMotionBee::Create(Math::Vector pos, float angle, ObjectType type,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(18, rank);
m_object->SetObjectParent(18, 0);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "ant4.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("ant4.mod", false, rank);
m_object->SetPosition(18, Math::Vector(1.0f, -0.1f, 0.7f));
m_object->SetAngleY(18, Math::PI);
@@ -262,8 +237,7 @@ bool CMotionBee::Create(Math::Vector pos, float angle, ObjectType type,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(19, rank);
m_object->SetObjectParent(19, 18);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "ant5.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("ant5.mod", false, rank);
m_object->SetPosition(19, Math::Vector(0.0f, 0.0f, -1.0f));
// Creates front-left foot.
@@ -271,8 +245,7 @@ bool CMotionBee::Create(Math::Vector pos, float angle, ObjectType type,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(20, rank);
m_object->SetObjectParent(20, 19);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "ant6.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("ant6.mod", false, rank);
m_object->SetPosition(20, Math::Vector(0.0f, 0.0f, -2.0f));
// Creates the right wing.
@@ -280,8 +253,7 @@ bool CMotionBee::Create(Math::Vector pos, float angle, ObjectType type,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(21, rank);
m_object->SetObjectParent(21, 0);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "bee7.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("bee7.mod", false, rank);
m_object->SetPosition(21, Math::Vector(0.8f, 0.4f, -0.5f));
// Creates the left wing.
@@ -289,9 +261,7 @@ bool CMotionBee::Create(Math::Vector pos, float angle, ObjectType type,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(22, rank);
m_object->SetObjectParent(22, 0);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "bee7.mod"));
- pModFile->Mirror();
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("bee7.mod", true, rank);
m_object->SetPosition(22, Math::Vector(0.8f, 0.4f, 0.5f));
m_object->CreateShadowCircle(6.0f, 0.5f);
@@ -304,7 +274,6 @@ bool CMotionBee::Create(Math::Vector pos, float angle, ObjectType type,
m_engine->LoadAllTextures();
- delete pModFile;
return true;
}
diff --git a/src/object/motion/motionhuman.cpp b/src/object/motion/motionhuman.cpp
index a9b79b5..5ff4af3 100644
--- a/src/object/motion/motionhuman.cpp
+++ b/src/object/motion/motionhuman.cpp
@@ -19,7 +19,7 @@
#include "app/app.h"
-#include "graphics/engine/modelfile.h"
+#include "graphics/engine/modelmanager.h"
#include "graphics/engine/terrain.h"
#include "graphics/engine/water.h"
@@ -97,30 +97,22 @@ Error CMotionHuman::SetAction(int action, float time)
bool CMotionHuman::Create(Math::Vector pos, float angle, ObjectType type,
float power)
{
- Gfx::CModelFile* pModFile;
char filename[100];
int rank, option, face, glasses;
-// if ( m_engine->GetRestCreate() < 16 ) return false;
-
-
- pModFile = new Gfx::CModelFile(m_iMan);
+ Gfx::CModelManager* modelManager = Gfx::CModelManager::GetInstancePointer();
m_object->SetType(type);
option = m_object->GetOption();
- std::string baseName;
-
if ( m_main->GetGamerOnlyHead() )
{
rank = m_engine->CreateObject();
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_VEHICULE); // this is a moving object
m_object->SetObjectRank(0, rank);
face = m_main->GetGamerFace();
- baseName = m_app->GetDataFilePath(DIR_MODEL, "human2h%d.mod");
- sprintf(filename, baseName.c_str(), face+1);
- pModFile->ReadModel(filename);
- pModFile->CreateEngineObject(rank);
+ sprintf(filename, "human2h%d.mod", face+1);
+ modelManager->AddModelReference(filename, false, rank);
glasses = m_main->GetGamerGlasses();
if ( glasses != 0 )
@@ -129,10 +121,8 @@ bool CMotionHuman::Create(Math::Vector pos, float angle, ObjectType type,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(1, rank);
m_object->SetObjectParent(1, 0);
- baseName = m_app->GetDataFilePath(DIR_MODEL, "human2g%d.mod");
- sprintf(filename, baseName.c_str(), glasses);
- pModFile->ReadModel(filename);
- pModFile->CreateEngineObject(rank);
+ sprintf(filename, "human2g%d.mod", glasses);
+ modelManager->AddModelReference(filename, false, rank);
}
CreatePhysics(type);
@@ -140,7 +130,6 @@ bool CMotionHuman::Create(Math::Vector pos, float angle, ObjectType type,
m_engine->LoadAllTextures();
- delete pModFile;
return true;
}
@@ -149,19 +138,12 @@ bool CMotionHuman::Create(Math::Vector pos, float angle, ObjectType type,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_VEHICULE); // this is a moving object
m_object->SetObjectRank(0, rank);
- if ( option == 0 ) // head in helmet?
- {
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "human1c.mod"));
- }
- if ( option == 1 ) // head without helmet?
- {
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "human1h.mod"));
- }
- if ( option == 2 ) // without a backpack?
- {
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "human1v.mod"));
- }
- pModFile->CreateEngineObject(rank);
+ if (option == 0) // head in helmet?
+ modelManager->AddModelReference("human1c.mod", false, rank);
+ else if (option == 1) // head without helmet?
+ modelManager->AddModelReference("human1h.mod", false, rank);
+ else if (option == 2) // without a backpack?
+ modelManager->AddModelReference("human1v.mod", false, rank);
m_object->SetPosition(0, pos);
m_object->SetAngleY(0, angle);
@@ -178,30 +160,28 @@ bool CMotionHuman::Create(Math::Vector pos, float angle, ObjectType type,
if ( type == OBJECT_HUMAN )
{
- if ( option == 0 ) // head in helmet?
+ if (option == 0) // head in helmet?
{
face = m_main->GetGamerFace();
- baseName = m_app->GetDataFilePath(DIR_MODEL, "human2c%d.mod");
- sprintf(filename, baseName.c_str(), face+1);
- pModFile->ReadModel(filename);
+ sprintf(filename, "human2c%d.mod", face+1);
+ modelManager->AddModelReference(filename, false, rank);
}
- if ( option == 1 || // head without helmet?
- option == 2 ) // without a backpack?
+ else if (option == 1 || // head without helmet?
+ option == 2) // without a backpack?
{
face = m_main->GetGamerFace();
- baseName = m_app->GetDataFilePath(DIR_MODEL, "human2h%d.mod");
- sprintf(filename, baseName.c_str(), face+1);
- pModFile->ReadModel(filename);
+ sprintf(filename, "human2h%d.mod", face+1);
+ modelManager->AddModelReference(filename, false, rank);
}
}
- if ( type == OBJECT_TECH )
+ else if (type == OBJECT_TECH)
{
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "human2t.mod"));
+ modelManager->AddModelReference("human2t.mod", false, rank);
}
- pModFile->CreateEngineObject(rank);
+
m_object->SetPosition(1, Math::Vector(0.0f, 2.7f, 0.0f));
- if ( option == 1 || // head without helmet?
- option == 2 ) // without a backpack?
+ if (option == 1 || // head without helmet?
+ option == 2) // without a backpack?
{
m_object->SetZoom(1, Math::Vector(1.0f, 1.05f, 1.0f));
}
@@ -214,10 +194,8 @@ bool CMotionHuman::Create(Math::Vector pos, float angle, ObjectType type,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(15, rank);
m_object->SetObjectParent(15, 1);
- baseName = m_app->GetDataFilePath(DIR_MODEL, "human2g%d.mod");
- sprintf(filename, baseName.c_str(), glasses);
- pModFile->ReadModel(filename);
- pModFile->CreateEngineObject(rank);
+ sprintf(filename, "human2g%d.mod", glasses);
+ modelManager->AddModelReference(filename, false, rank);
}
// Creates the right arm.
@@ -225,8 +203,7 @@ bool CMotionHuman::Create(Math::Vector pos, float angle, ObjectType type,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(2, rank);
m_object->SetObjectParent(2, 0);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "human3.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("human3.mod", false, rank);
m_object->SetPosition(2, Math::Vector(0.0f, 2.3f, -1.2f));
m_object->SetAngle(2, Math::Vector(90.0f*Math::PI/180.0f, 90.0f*Math::PI/180.0f, -50.0f*Math::PI/180.0f));
@@ -235,8 +212,7 @@ bool CMotionHuman::Create(Math::Vector pos, float angle, ObjectType type,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(3, rank);
m_object->SetObjectParent(3, 2);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "human4r.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("human4r.mod", false, rank);
m_object->SetPosition(3, Math::Vector(1.3f, 0.0f, 0.0f));
m_object->SetAngle(3, Math::Vector(0.0f*Math::PI/180.0f, -20.0f*Math::PI/180.0f, 0.0f*Math::PI/180.0f));
@@ -245,8 +221,7 @@ bool CMotionHuman::Create(Math::Vector pos, float angle, ObjectType type,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(4, rank);
m_object->SetObjectParent(4, 3);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "human5.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("human5.mod", false, rank);
m_object->SetPosition(4, Math::Vector(1.2f, 0.0f, 0.0f));
// Creates the right thigh.
@@ -254,8 +229,7 @@ bool CMotionHuman::Create(Math::Vector pos, float angle, ObjectType type,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(5, rank);
m_object->SetObjectParent(5, 0);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "human6.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("human6.mod", false, rank);
m_object->SetPosition(5, Math::Vector(0.0f, 0.0f, -0.7f));
m_object->SetAngle(5, Math::Vector(10.0f*Math::PI/180.0f, 0.0f*Math::PI/180.0f, 5.0f*Math::PI/180.0f));
@@ -264,8 +238,7 @@ bool CMotionHuman::Create(Math::Vector pos, float angle, ObjectType type,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(6, rank);
m_object->SetObjectParent(6, 5);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "human7.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("human7.mod", false, rank);
m_object->SetPosition(6, Math::Vector(0.0f, -1.5f, 0.0f));
m_object->SetAngle(6, Math::Vector(0.0f*Math::PI/180.0f, 0.0f*Math::PI/180.0f, -10.0f*Math::PI/180.0f));
@@ -274,8 +247,7 @@ bool CMotionHuman::Create(Math::Vector pos, float angle, ObjectType type,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(7, rank);
m_object->SetObjectParent(7, 6);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "human8.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("human8.mod", false, rank);
m_object->SetPosition(7, Math::Vector(0.0f, -1.5f, 0.0f));
m_object->SetAngle(7, Math::Vector(-10.0f*Math::PI/180.0f, 5.0f*Math::PI/180.0f, 5.0f*Math::PI/180.0f));
@@ -284,9 +256,7 @@ bool CMotionHuman::Create(Math::Vector pos, float angle, ObjectType type,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(8, rank);
m_object->SetObjectParent(8, 0);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "human3.mod"));
- pModFile->Mirror();
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("human3.mod", true, rank);
m_object->SetPosition(8, Math::Vector(0.0f, 2.3f, 1.2f));
m_object->SetAngle(8, Math::Vector(-90.0f*Math::PI/180.0f, -90.0f*Math::PI/180.0f, -50.0f*Math::PI/180.0f));
@@ -295,9 +265,7 @@ bool CMotionHuman::Create(Math::Vector pos, float angle, ObjectType type,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(9, rank);
m_object->SetObjectParent(9, 8);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "human4l.mod"));
- pModFile->Mirror();
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("human4l.mod", true, rank);
m_object->SetPosition(9, Math::Vector(1.3f, 0.0f, 0.0f));
m_object->SetAngle(9, Math::Vector(0.0f*Math::PI/180.0f, 20.0f*Math::PI/180.0f, 0.0f*Math::PI/180.0f));
@@ -306,9 +274,7 @@ bool CMotionHuman::Create(Math::Vector pos, float angle, ObjectType type,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(10, rank);
m_object->SetObjectParent(10, 9);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "human5.mod"));
- pModFile->Mirror();
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("human5.mod", true, rank);
m_object->SetPosition(10, Math::Vector(1.2f, 0.0f, 0.0f));
// Creates the left thigh.
@@ -316,9 +282,7 @@ bool CMotionHuman::Create(Math::Vector pos, float angle, ObjectType type,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(11, rank);
m_object->SetObjectParent(11, 0);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "human6.mod"));
- pModFile->Mirror();
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("human6.mod", true, rank);
m_object->SetPosition(11, Math::Vector(0.0f, 0.0f, 0.7f));
m_object->SetAngle(11, Math::Vector(-10.0f*Math::PI/180.0f, 0.0f*Math::PI/180.0f, 5.0f*Math::PI/180.0f));
@@ -327,9 +291,7 @@ bool CMotionHuman::Create(Math::Vector pos, float angle, ObjectType type,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(12, rank);
m_object->SetObjectParent(12, 11);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "human7.mod"));
- pModFile->Mirror();
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("human7.mod", true, rank);
m_object->SetPosition(12, Math::Vector(0.0f, -1.5f, 0.0f));
m_object->SetAngle(12, Math::Vector(0.0f*Math::PI/180.0f, 0.0f*Math::PI/180.0f, -10.0f*Math::PI/180.0f));
@@ -338,9 +300,7 @@ bool CMotionHuman::Create(Math::Vector pos, float angle, ObjectType type,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(13, rank);
m_object->SetObjectParent(13, 12);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "human8.mod"));
- pModFile->Mirror();
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("human8.mod", true, rank);
m_object->SetPosition(13, Math::Vector(0.0f, -1.5f, 0.0f));
m_object->SetAngle(13, Math::Vector(10.0f*Math::PI/180.0f, -5.0f*Math::PI/180.0f, 5.0f*Math::PI/180.0f));
@@ -351,8 +311,7 @@ bool CMotionHuman::Create(Math::Vector pos, float angle, ObjectType type,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(14, rank);
m_object->SetObjectParent(14, 0);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "human9.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("human9.mod", false, rank);
m_object->SetPosition(14, Math::Vector(-1.5f, 0.3f, -1.35f));
m_object->SetAngleZ(14, Math::PI);
}
@@ -367,7 +326,6 @@ bool CMotionHuman::Create(Math::Vector pos, float angle, ObjectType type,
m_engine->LoadAllTextures();
- delete pModFile;
return true;
}
diff --git a/src/object/motion/motionmother.cpp b/src/object/motion/motionmother.cpp
index 8ea77a5..ce1362f 100644
--- a/src/object/motion/motionmother.cpp
+++ b/src/object/motion/motionmother.cpp
@@ -19,7 +19,7 @@
#include "app/app.h"
-#include "graphics/engine/modelfile.h"
+#include "graphics/engine/modelmanager.h"
#include "physics/physics.h"
@@ -68,12 +68,8 @@ void CMotionMother::DeleteObject(bool bAll)
bool CMotionMother::Create(Math::Vector pos, float angle, ObjectType type,
float power)
{
- Gfx::CModelFile* pModFile;
- int rank;
-
-// if ( m_engine->GetRestCreate() < 2+12+6 ) return false;
-
- pModFile = new Gfx::CModelFile(m_iMan);
+ Gfx::CModelManager* modelManager = Gfx::CModelManager::GetInstancePointer();
+ int rank;
m_object->SetType(type);
@@ -81,10 +77,7 @@ bool CMotionMother::Create(Math::Vector pos, float angle, ObjectType type,
rank = m_engine->CreateObject();
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_VEHICULE); // this is a moving object
m_object->SetObjectRank(0, rank);
-
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "mother1.mod"));
- pModFile->CreateEngineObject(rank);
-
+ modelManager->AddModelReference("mother1.mod", false, rank);
m_object->SetPosition(0, pos);
m_object->SetAngleY(0, angle);
@@ -98,8 +91,7 @@ bool CMotionMother::Create(Math::Vector pos, float angle, ObjectType type,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(1, rank);
m_object->SetObjectParent(1, 0);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "mother2.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("mother2.mod", false, rank);
m_object->SetPosition(1, Math::Vector(16.0f, 3.0f, 0.0f));
// Creates a right-back leg.
@@ -107,8 +99,7 @@ bool CMotionMother::Create(Math::Vector pos, float angle, ObjectType type,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(2, rank);
m_object->SetObjectParent(2, 0);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "mother3.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("mother3.mod", false, rank);
m_object->SetPosition(2, Math::Vector(-5.0f, -1.0f, -12.0f));
// Creates a right-back foot.
@@ -116,8 +107,7 @@ bool CMotionMother::Create(Math::Vector pos, float angle, ObjectType type,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(3, rank);
m_object->SetObjectParent(3, 2);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "mother4.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("mother4.mod", false, rank);
m_object->SetPosition(3, Math::Vector(0.0f, 0.0f, -8.5f));
// Creates a middle-right leg.
@@ -125,8 +115,7 @@ bool CMotionMother::Create(Math::Vector pos, float angle, ObjectType type,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(4, rank);
m_object->SetObjectParent(4, 0);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "mother3.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("mother3.mod", false, rank);
m_object->SetPosition(4, Math::Vector(3.5f, -1.0f, -12.0f));
// Creates a middle-right foot.
@@ -134,8 +123,7 @@ bool CMotionMother::Create(Math::Vector pos, float angle, ObjectType type,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(5, rank);
m_object->SetObjectParent(5, 4);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "mother4.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("mother4.mod", false, rank);
m_object->SetPosition(5, Math::Vector(0.0f, 0.0f, -8.5f));
// Creates a right-front leg.
@@ -143,8 +131,7 @@ bool CMotionMother::Create(Math::Vector pos, float angle, ObjectType type,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(6, rank);
m_object->SetObjectParent(6, 0);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "mother3.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("mother3.mod", false, rank);
m_object->SetPosition(6, Math::Vector(10.0f, -1.0f, -10.0f));
// Creates a right-front foot.
@@ -152,8 +139,7 @@ bool CMotionMother::Create(Math::Vector pos, float angle, ObjectType type,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(7, rank);
m_object->SetObjectParent(7, 6);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "mother4.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("mother4.mod", false, rank);
m_object->SetPosition(7, Math::Vector(0.0f, 0.0f, -8.5f));
// Creates a left-back leg.
@@ -161,8 +147,7 @@ bool CMotionMother::Create(Math::Vector pos, float angle, ObjectType type,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(8, rank);
m_object->SetObjectParent(8, 0);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "mother3.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("mother3.mod", false, rank);
m_object->SetPosition(8, Math::Vector(-5.0f, -1.0f, 12.0f));
m_object->SetAngleY(8, Math::PI);
@@ -171,8 +156,7 @@ bool CMotionMother::Create(Math::Vector pos, float angle, ObjectType type,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(9, rank);
m_object->SetObjectParent(9, 8);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "mother4.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("mother4.mod", false, rank);
m_object->SetPosition(9, Math::Vector(0.0f, 0.0f, -8.5f));
// Creates a middle-left leg.
@@ -180,8 +164,7 @@ bool CMotionMother::Create(Math::Vector pos, float angle, ObjectType type,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(10, rank);
m_object->SetObjectParent(10, 0);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "mother3.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("mother3.mod", false, rank);
m_object->SetPosition(10, Math::Vector(3.5f, -1.0f, 12.0f));
m_object->SetAngleY(10, Math::PI);
@@ -190,8 +173,7 @@ bool CMotionMother::Create(Math::Vector pos, float angle, ObjectType type,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(11, rank);
m_object->SetObjectParent(11, 10);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "mother4.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("mother4.mod", false, rank);
m_object->SetPosition(11, Math::Vector(0.0f, 0.0f, -8.5f));
// Creates a left-front leg.
@@ -199,8 +181,7 @@ bool CMotionMother::Create(Math::Vector pos, float angle, ObjectType type,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(12, rank);
m_object->SetObjectParent(12, 0);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "mother3.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("mother3.mod", false, rank);
m_object->SetPosition(12, Math::Vector(10.0f, -1.0f, 10.0f));
m_object->SetAngleY(12, Math::PI);
@@ -209,8 +190,7 @@ bool CMotionMother::Create(Math::Vector pos, float angle, ObjectType type,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(13, rank);
m_object->SetObjectParent(13, 12);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "mother4.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("mother4.mod", false, rank);
m_object->SetPosition(13, Math::Vector(0.0f, 0.0f, -8.5f));
// Creates the right antenna.
@@ -218,16 +198,14 @@ bool CMotionMother::Create(Math::Vector pos, float angle, ObjectType type,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(14, rank);
m_object->SetObjectParent(14, 1);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "mother5.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("mother5.mod", false, rank);
m_object->SetPosition(14, Math::Vector(6.0f, 1.0f, -2.5f));
rank = m_engine->CreateObject();
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(15, rank);
m_object->SetObjectParent(15, 14);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "mother6.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("mother6.mod", false, rank);
m_object->SetPosition(15, Math::Vector(8.0f, 0.0f, 0.0f));
// Creates the left antenna.
@@ -235,16 +213,14 @@ bool CMotionMother::Create(Math::Vector pos, float angle, ObjectType type,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(16, rank);
m_object->SetObjectParent(16, 1);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "mother5.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("mother5.mod", false, rank);
m_object->SetPosition(16, Math::Vector(6.0f, 1.0f, 2.5f));
rank = m_engine->CreateObject();
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(17, rank);
m_object->SetObjectParent(17, 16);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "mother6.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("mother6.mod", false, rank);
m_object->SetPosition(17, Math::Vector(8.0f, 0.0f, 0.0f));
// Creates the right claw.
@@ -252,8 +228,7 @@ bool CMotionMother::Create(Math::Vector pos, float angle, ObjectType type,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(18, rank);
m_object->SetObjectParent(18, 1);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "mother7.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("mother7.mod", false, rank);
m_object->SetPosition(18, Math::Vector(-4.0f, -3.5f, -8.0f));
m_object->SetZoomX(18, 1.2f);
@@ -262,9 +237,7 @@ bool CMotionMother::Create(Math::Vector pos, float angle, ObjectType type,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(19, rank);
m_object->SetObjectParent(19, 1);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "mother7.mod"));
- pModFile->Mirror();
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("mother7.mod", true, rank);
m_object->SetPosition(19, Math::Vector(-4.0f, -3.5f, 8.0f));
m_object->SetZoomX(19, 1.2f);
@@ -278,7 +251,6 @@ bool CMotionMother::Create(Math::Vector pos, float angle, ObjectType type,
m_engine->LoadAllTextures();
- delete pModFile;
return true;
}
diff --git a/src/object/motion/motionspider.cpp b/src/object/motion/motionspider.cpp
index 516ec6e..3ede492 100644
--- a/src/object/motion/motionspider.cpp
+++ b/src/object/motion/motionspider.cpp
@@ -19,7 +19,7 @@
#include "app/app.h"
-#include "graphics/engine/modelfile.h"
+#include "graphics/engine/modelmanager.h"
#include "graphics/engine/particle.h"
#include "physics/physics.h"
@@ -69,12 +69,9 @@ void CMotionSpider::DeleteObject(bool bAll)
bool CMotionSpider::Create(Math::Vector pos, float angle, ObjectType type,
float power)
{
- Gfx::CModelFile* pModFile;
int rank, i, j, parent;
char name[50];
- std::string baseName;
-
float table[] =
{
// x y z
@@ -99,9 +96,7 @@ bool CMotionSpider::Create(Math::Vector pos, float angle, ObjectType type,
0.0f, 0.0f, -2.0f,
};
-// if ( m_engine->GetRestCreate() < 3+32+2 ) return false;
-
- pModFile = new Gfx::CModelFile(m_iMan);
+ Gfx::CModelManager* modelManager = Gfx::CModelManager::GetInstancePointer();
m_object->SetType(type);
@@ -109,8 +104,7 @@ bool CMotionSpider::Create(Math::Vector pos, float angle, ObjectType type,
rank = m_engine->CreateObject();
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_VEHICULE); // this is a moving object
m_object->SetObjectRank(0, rank);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "spider0.mod")); // doesn't exist
- pModFile->CreateEngineObject(rank);
+ // This is an "empty" object, without triangles
m_object->SetPosition(0, pos);
m_object->SetAngleY(0, angle);
@@ -124,8 +118,7 @@ bool CMotionSpider::Create(Math::Vector pos, float angle, ObjectType type,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(1, rank);
m_object->SetObjectParent(1, 0);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "spider1.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("spider1.mod", false, rank);
m_object->SetPosition(1, Math::Vector(1.0f, 0.0f, 0.0f));
// Creates the head.
@@ -133,8 +126,7 @@ bool CMotionSpider::Create(Math::Vector pos, float angle, ObjectType type,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(2, rank);
m_object->SetObjectParent(2, 0);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "spider2.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("spider2.mod", false, rank);
m_object->SetPosition(2, Math::Vector(1.0f, 0.0f, 0.0f));
// Creates legs.
@@ -142,8 +134,7 @@ bool CMotionSpider::Create(Math::Vector pos, float angle, ObjectType type,
{
for ( j=0 ; j<4 ; j++ )
{
- baseName = m_app->GetDataFilePath(DIR_MODEL, "spider%d.mod");
- sprintf(name, baseName.c_str(), j+3); // 3..6
+ sprintf(name, "spider%d.mod", j+3); // 3..6
// Creates the right leg.
rank = m_engine->CreateObject();
@@ -152,8 +143,7 @@ bool CMotionSpider::Create(Math::Vector pos, float angle, ObjectType type,
if ( j == 0 ) parent = 0;
else parent = 3+i*4+j-1;
m_object->SetObjectParent(3+i*4+j, parent);
- pModFile->ReadModel(name);
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference(name, false, rank);
pos.x = table[i*12+j*3+0];
pos.y = table[i*12+j*3+1];
pos.z = table[i*12+j*3+2];
@@ -166,9 +156,7 @@ bool CMotionSpider::Create(Math::Vector pos, float angle, ObjectType type,
if ( j == 0 ) parent = 0;
else parent = 19+i*4+j-1;
m_object->SetObjectParent(19+i*4+j, parent);
- pModFile->ReadModel(name);
- pModFile->Mirror();
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference(name, true, rank);
pos.x = table[i*12+j*3+0];
pos.y = table[i*12+j*3+1];
pos.z = -table[i*12+j*3+2];
@@ -181,8 +169,7 @@ bool CMotionSpider::Create(Math::Vector pos, float angle, ObjectType type,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(35, rank);
m_object->SetObjectParent(35, 1);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "spider7.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("spider7.mod", false, rank);
m_object->SetPosition(35, Math::Vector(0.0f, 0.0f, -0.3f));
// Creates the left mandible.
@@ -190,9 +177,7 @@ bool CMotionSpider::Create(Math::Vector pos, float angle, ObjectType type,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(36, rank);
m_object->SetObjectParent(36, 1);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "spider7.mod"));
- pModFile->Mirror();
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("spider7.mod", true, rank);
m_object->SetPosition(36, Math::Vector(0.0f, 0.0f, 0.3f));
m_object->CreateShadowCircle(4.0f, 0.5f);
@@ -205,7 +190,6 @@ bool CMotionSpider::Create(Math::Vector pos, float angle, ObjectType type,
m_engine->LoadAllTextures();
- delete pModFile;
return true;
}
diff --git a/src/object/motion/motiontoto.cpp b/src/object/motion/motiontoto.cpp
index 274f171..3a7f1ac 100644
--- a/src/object/motion/motiontoto.cpp
+++ b/src/object/motion/motiontoto.cpp
@@ -21,9 +21,9 @@
#include "math/geometry.h"
+#include "graphics/engine/modelmanager.h"
#include "graphics/engine/terrain.h"
#include "graphics/engine/water.h"
-#include "graphics/engine/modelfile.h"
#include "object/robotmain.h"
@@ -81,12 +81,9 @@ void CMotionToto::DeleteObject(bool bAll)
bool CMotionToto::Create(Math::Vector pos, float angle, ObjectType type,
float power)
{
- Gfx::CModelFile* pModFile;
+ Gfx::CModelManager* modelManager = Gfx::CModelManager::GetInstancePointer();
int rank;
-// if ( m_engine->GetRestCreate() < 10 ) return false;
-
- pModFile = new Gfx::CModelFile(m_iMan);
m_object->SetType(type);
@@ -94,8 +91,7 @@ bool CMotionToto::Create(Math::Vector pos, float angle, ObjectType type,
rank = m_engine->CreateObject();
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_VEHICULE); // this is a moving object
m_object->SetObjectRank(0, rank);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "toto1.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("toto1.mod", false, rank);
m_object->SetPosition(0, pos);
m_object->SetAngleY(0, angle);
@@ -104,8 +100,7 @@ bool CMotionToto::Create(Math::Vector pos, float angle, ObjectType type,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(1, rank);
m_object->SetObjectParent(1, 0);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "toto2.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("toto2.mod", false, rank);
m_object->SetPosition(1, Math::Vector(1.00f, 0.17f, 0.00f));
// Creates the left eye.
@@ -113,9 +108,7 @@ bool CMotionToto::Create(Math::Vector pos, float angle, ObjectType type,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(2, rank);
m_object->SetObjectParent(2, 0);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "toto3.mod"));
- pModFile->Mirror();
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("toto3.mod", true, rank);
m_object->SetPosition(2, Math::Vector(0.85f, 1.04f, 0.25f));
m_object->SetAngleY(2, -20.0f*Math::PI/180.0f);
@@ -124,8 +117,7 @@ bool CMotionToto::Create(Math::Vector pos, float angle, ObjectType type,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(3, rank);
m_object->SetObjectParent(3, 0);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "toto3.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("toto3.mod", false, rank);
m_object->SetPosition(3, Math::Vector(0.85f, 1.04f, -0.25f));
m_object->SetAngleY(3, 20.0f*Math::PI/180.0f);
@@ -134,8 +126,7 @@ bool CMotionToto::Create(Math::Vector pos, float angle, ObjectType type,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(4, rank);
m_object->SetObjectParent(4, 0);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "toto4.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("toto4.mod", false, rank);
m_object->SetPosition(4, Math::Vector(0.0f, 1.9f, 0.3f));
m_object->SetAngleX(4, 30.0f*Math::PI/180.0f);
@@ -143,8 +134,7 @@ bool CMotionToto::Create(Math::Vector pos, float angle, ObjectType type,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(5, rank);
m_object->SetObjectParent(5, 4);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "toto4.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("toto4.mod", false, rank);
m_object->SetPosition(5, Math::Vector(0.0f, 0.67f, 0.0f));
m_object->SetAngleX(5, 30.0f*Math::PI/180.0f);
@@ -152,8 +142,7 @@ bool CMotionToto::Create(Math::Vector pos, float angle, ObjectType type,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(6, rank);
m_object->SetObjectParent(6, 5);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "toto5.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("toto5.mod", false, rank);
m_object->SetPosition(6, Math::Vector(0.0f, 0.70f, 0.0f));
m_object->SetAngleX(6, 30.0f*Math::PI/180.0f);
@@ -162,8 +151,7 @@ bool CMotionToto::Create(Math::Vector pos, float angle, ObjectType type,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(7, rank);
m_object->SetObjectParent(7, 0);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "toto4.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("toto4.mod", false, rank);
m_object->SetPosition(7, Math::Vector(0.0f, 1.9f, -0.3f));
m_object->SetAngleX(7, -30.0f*Math::PI/180.0f);
@@ -171,8 +159,7 @@ bool CMotionToto::Create(Math::Vector pos, float angle, ObjectType type,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(8, rank);
m_object->SetObjectParent(8, 7);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "toto4.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("toto4.mod", false, rank);
m_object->SetPosition(8, Math::Vector(0.0f, 0.67f, 0.0f));
m_object->SetAngleX(8, -30.0f*Math::PI/180.0f);
@@ -180,8 +167,7 @@ bool CMotionToto::Create(Math::Vector pos, float angle, ObjectType type,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(9, rank);
m_object->SetObjectParent(9, 8);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "toto5.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("toto5.mod", false, rank);
m_object->SetPosition(9, Math::Vector(0.0f, 0.70f, 0.0f));
m_object->SetAngleX(9, -30.0f*Math::PI/180.0f);
@@ -193,7 +179,6 @@ bool CMotionToto::Create(Math::Vector pos, float angle, ObjectType type,
m_engine->LoadAllTextures();
- delete pModFile;
return true;
}
diff --git a/src/object/motion/motionvehicle.cpp b/src/object/motion/motionvehicle.cpp
index 849d53e..33e746f 100644
--- a/src/object/motion/motionvehicle.cpp
+++ b/src/object/motion/motionvehicle.cpp
@@ -19,7 +19,7 @@
#include "app/app.h"
-#include "graphics/engine/modelfile.h"
+#include "graphics/engine/modelmanager.h"
#include "graphics/engine/particle.h"
#include "graphics/engine/terrain.h"
@@ -92,15 +92,12 @@ void CMotionVehicle::DeleteObject(bool bAll)
bool CMotionVehicle::Create(Math::Vector pos, float angle, ObjectType type,
float power)
{
- Gfx::CModelFile* pModFile;
CObject* pPower;
int rank, i, j, parent;
Gfx::Color color;
char name[50];
-// if ( m_engine->GetRestCreate() < 1+5+18+1 ) return false;
-
- pModFile = new Gfx::CModelFile(m_iMan);
+ Gfx::CModelManager* modelManager = Gfx::CModelManager::GetInstancePointer();
m_object->SetType(type);
@@ -109,106 +106,105 @@ bool CMotionVehicle::Create(Math::Vector pos, float angle, ObjectType type,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_VEHICULE); // this is a moving object
m_object->SetObjectRank(0, rank);
- if ( type == OBJECT_MOBILEfa ||
- type == OBJECT_MOBILEfc ||
- type == OBJECT_MOBILEfi ||
- type == OBJECT_MOBILEfs )
+ if (type == OBJECT_MOBILEfa ||
+ type == OBJECT_MOBILEfc ||
+ type == OBJECT_MOBILEfi ||
+ type == OBJECT_MOBILEfs)
{
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "lem1f.mod"));
+ modelManager->AddModelReference("lem1f.mod", false, rank);
}
- if ( type == OBJECT_MOBILEta ||
- type == OBJECT_MOBILEtc ||
- type == OBJECT_MOBILEti ||
- type == OBJECT_MOBILEts )
+ else if (type == OBJECT_MOBILEta ||
+ type == OBJECT_MOBILEtc ||
+ type == OBJECT_MOBILEti ||
+ type == OBJECT_MOBILEts)
{
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "lem1t.mod"));
+ modelManager->AddModelReference("lem1t.mod", false, rank);
}
- if ( type == OBJECT_MOBILEwa ||
- type == OBJECT_MOBILEwc ||
- type == OBJECT_MOBILEwi ||
- type == OBJECT_MOBILEws )
+ else if (type == OBJECT_MOBILEwa ||
+ type == OBJECT_MOBILEwc ||
+ type == OBJECT_MOBILEwi ||
+ type == OBJECT_MOBILEws)
{
- if ( m_object->GetTrainer() )
+ if (m_object->GetTrainer())
{
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "lem1wt.mod"));
+ modelManager->AddModelReference("lem1wt.mod", false, rank);
}
else
{
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "lem1w.mod"));
+ modelManager->AddModelReference("lem1w.mod", false, rank);
}
}
- if ( type == OBJECT_MOBILEia ||
- type == OBJECT_MOBILEic ||
- type == OBJECT_MOBILEii ||
- type == OBJECT_MOBILEis )
+ else if (type == OBJECT_MOBILEia ||
+ type == OBJECT_MOBILEic ||
+ type == OBJECT_MOBILEii ||
+ type == OBJECT_MOBILEis)
{
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "lem1i.mod"));
+ modelManager->AddModelReference("lem1i.mod", false, rank);
}
- if ( type == OBJECT_MOBILErt ||
- type == OBJECT_MOBILErc ||
- type == OBJECT_MOBILErr ||
- type == OBJECT_MOBILErs )
+ else if (type == OBJECT_MOBILErt ||
+ type == OBJECT_MOBILErc ||
+ type == OBJECT_MOBILErr ||
+ type == OBJECT_MOBILErs)
{
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "roller1.mod"));
+ modelManager->AddModelReference("roller1.mod", false, rank);
}
- if ( type == OBJECT_MOBILEsa )
+ else if (type == OBJECT_MOBILEsa)
{
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "subm1.mod"));
+ modelManager->AddModelReference("subm1.mod", false, rank);
}
- if ( type == OBJECT_MOBILEtg )
+ else if (type == OBJECT_MOBILEtg)
{
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "target.mod"));
+ modelManager->AddModelReference("target.mod", false, rank);
}
- if ( type == OBJECT_MOBILEwt )
+ else if (type == OBJECT_MOBILEwt)
{
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "trainerw.mod"));
+ modelManager->AddModelReference("trainerw.mod", false, rank);
}
- if ( type == OBJECT_MOBILEft )
+ else if (type == OBJECT_MOBILEft)
{
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "trainerf.mod"));
+ modelManager->AddModelReference("trainerf.mod", false, rank);
}
- if ( type == OBJECT_MOBILEtt )
+ else if (type == OBJECT_MOBILEtt)
{
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "trainert.mod"));
+ modelManager->AddModelReference("trainert.mod", false, rank);
}
- if ( type == OBJECT_MOBILEit )
+ else if (type == OBJECT_MOBILEit)
{
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "traineri.mod"));
+ modelManager->AddModelReference("traineri.mod", false, rank);
}
- if ( type == OBJECT_MOBILEdr )
+ else if (type == OBJECT_MOBILEdr)
{
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "drawer1.mod"));
+ modelManager->AddModelReference("drawer1.mod", false, rank);
}
- if ( type == OBJECT_APOLLO2 )
+ else if (type == OBJECT_APOLLO2)
{
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "apolloj1.mod"));
+ modelManager->AddModelReference("apolloj1.mod", false, rank);
}
- pModFile->CreateEngineObject(rank);
m_object->SetPosition(0, pos);
m_object->SetAngleY(0, angle);
// A vehicle must have a obligatory collision
// with a sphere of center (0, y, 0) (see GetCrashSphere).
- if ( type == OBJECT_MOBILErt ||
- type == OBJECT_MOBILErc ||
- type == OBJECT_MOBILErr ||
- type == OBJECT_MOBILErs )
+ if (type == OBJECT_MOBILErt ||
+ type == OBJECT_MOBILErc ||
+ type == OBJECT_MOBILErr ||
+ type == OBJECT_MOBILErs)
{
m_object->CreateCrashSphere(Math::Vector(0.0f, 4.0f, 0.0f), 6.5f, SOUND_BOUMm, 0.45f);
m_object->SetGlobalSphere(Math::Vector(0.0f, 3.0f, 0.0f), 7.0f);
}
- else if ( type == OBJECT_MOBILEsa )
+ else if (type == OBJECT_MOBILEsa)
{
m_object->CreateCrashSphere(Math::Vector(0.0f, 3.0f, 0.0f), 4.5f, SOUND_BOUMm, 0.45f);
m_object->SetGlobalSphere(Math::Vector(0.0f, 3.0f, 0.0f), 6.0f);
}
- else if ( type == OBJECT_MOBILEdr )
+ else if (type == OBJECT_MOBILEdr)
{
m_object->CreateCrashSphere(Math::Vector(0.0f, 3.0f, 0.0f), 5.0f, SOUND_BOUMm, 0.45f);
m_object->SetGlobalSphere(Math::Vector(0.0f, 3.0f, 0.0f), 7.0f);
}
- else if ( type == OBJECT_APOLLO2 )
+ else if (type == OBJECT_APOLLO2)
{
m_object->CreateCrashSphere(Math::Vector(0.0f, 0.0f, 0.0f), 8.0f, SOUND_BOUMm, 0.45f);
}
@@ -218,18 +214,17 @@ bool CMotionVehicle::Create(Math::Vector pos, float angle, ObjectType type,
m_object->SetGlobalSphere(Math::Vector(0.0f, 4.0f, 0.0f), 6.0f);
}
- if ( type == OBJECT_MOBILEfa ||
- type == OBJECT_MOBILEta ||
- type == OBJECT_MOBILEwa ||
- type == OBJECT_MOBILEia )
+ if (type == OBJECT_MOBILEfa ||
+ type == OBJECT_MOBILEta ||
+ type == OBJECT_MOBILEwa ||
+ type == OBJECT_MOBILEia)
{
// Creates the arm.
rank = m_engine->CreateObject();
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(1, rank);
m_object->SetObjectParent(1, 0);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "lem2.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("lem2.mod", false, rank);
m_object->SetPosition(1, Math::Vector(0.0f, 5.3f, 0.0f));
m_object->SetAngleZ(1, ARM_NEUTRAL_ANGLE1);
@@ -238,8 +233,7 @@ bool CMotionVehicle::Create(Math::Vector pos, float angle, ObjectType type,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(2, rank);
m_object->SetObjectParent(2, 1);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "lem3.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("lem3.mod", false, rank);
m_object->SetPosition(2, Math::Vector(5.0f, 0.0f, 0.0f));
m_object->SetAngleZ(2, ARM_NEUTRAL_ANGLE2);
@@ -248,8 +242,7 @@ bool CMotionVehicle::Create(Math::Vector pos, float angle, ObjectType type,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(3, rank);
m_object->SetObjectParent(3, 2);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "lem4.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("lem4.mod", false, rank);
m_object->SetPosition(3, Math::Vector(3.5f, 0.0f, 0.0f));
m_object->SetAngleZ(3, ARM_NEUTRAL_ANGLE3);
m_object->SetAngleX(3, Math::PI/2.0f);
@@ -259,8 +252,7 @@ bool CMotionVehicle::Create(Math::Vector pos, float angle, ObjectType type,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(4, rank);
m_object->SetObjectParent(4, 3);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "lem5.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("lem5.mod", false, rank);
m_object->SetPosition(4, Math::Vector(1.5f, 0.0f, 0.0f));
m_object->SetAngleZ(4, -Math::PI*0.10f);
@@ -269,24 +261,22 @@ bool CMotionVehicle::Create(Math::Vector pos, float angle, ObjectType type,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(5, rank);
m_object->SetObjectParent(5, 3);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "lem6.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("lem6.mod", false, rank);
m_object->SetPosition(5, Math::Vector(1.5f, 0.0f, 0.0f));
m_object->SetAngleZ(5, Math::PI*0.10f);
}
- if ( type == OBJECT_MOBILEfs ||
- type == OBJECT_MOBILEts ||
- type == OBJECT_MOBILEws ||
- type == OBJECT_MOBILEis )
+ if (type == OBJECT_MOBILEfs ||
+ type == OBJECT_MOBILEts ||
+ type == OBJECT_MOBILEws ||
+ type == OBJECT_MOBILEis)
{
// Creates the arm.
rank = m_engine->CreateObject();
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(1, rank);
m_object->SetObjectParent(1, 0);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "lem2.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("lem2.mod", false, rank);
m_object->SetPosition(1, Math::Vector(0.0f, 5.3f, 0.0f));
m_object->SetAngleZ(1, 110.0f*Math::PI/180.0f);
@@ -295,8 +285,7 @@ bool CMotionVehicle::Create(Math::Vector pos, float angle, ObjectType type,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(2, rank);
m_object->SetObjectParent(2, 1);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "lem3.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("lem3.mod", false, rank);
m_object->SetPosition(2, Math::Vector(5.0f, 0.0f, 0.0f));
m_object->SetAngleZ(2, -110.0f*Math::PI/180.0f);
@@ -305,41 +294,38 @@ bool CMotionVehicle::Create(Math::Vector pos, float angle, ObjectType type,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(3, rank);
m_object->SetObjectParent(3, 2);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "lem4s.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("lem4s.mod", false, rank);
m_object->SetPosition(3, Math::Vector(3.5f, 0.0f, 0.0f));
m_object->SetAngleZ(3, -65.0f*Math::PI/180.0f);
}
- if ( type == OBJECT_MOBILEfc ||
- type == OBJECT_MOBILEtc ||
- type == OBJECT_MOBILEwc ||
- type == OBJECT_MOBILEic )
+ if (type == OBJECT_MOBILEfc ||
+ type == OBJECT_MOBILEtc ||
+ type == OBJECT_MOBILEwc ||
+ type == OBJECT_MOBILEic)
{
// Creates the cannon.
rank = m_engine->CreateObject();
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(1, rank);
m_object->SetObjectParent(1, 0);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "canon.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("canon.mod", false, rank);
//? m_object->SetPosition(1, Math::Vector(0.0f, 5.3f, 0.0f));
m_object->SetPosition(1, Math::Vector(0.0f, 5.3f, 0.0f));
m_object->SetAngleZ(1, 0.0f);
}
- if ( type == OBJECT_MOBILEfi ||
- type == OBJECT_MOBILEti ||
- type == OBJECT_MOBILEwi ||
- type == OBJECT_MOBILEii )
+ if (type == OBJECT_MOBILEfi ||
+ type == OBJECT_MOBILEti ||
+ type == OBJECT_MOBILEwi ||
+ type == OBJECT_MOBILEii)
{
// Creates the insect cannon.
rank = m_engine->CreateObject();
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(1, rank);
m_object->SetObjectParent(1, 0);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "canoni1.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("canoni1.mod", false, rank);
m_object->SetPosition(1, Math::Vector(0.0f, 5.3f, 0.0f));
m_object->SetAngleZ(1, 0.0f);
@@ -347,25 +333,23 @@ bool CMotionVehicle::Create(Math::Vector pos, float angle, ObjectType type,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(2, rank);
m_object->SetObjectParent(2, 1);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "canoni2.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("canoni2.mod", false, rank);
m_object->SetPosition(2, Math::Vector(0.0f, 2.5f, 0.0f));
m_object->SetAngleZ(2, 0.0f);
}
- if ( type == OBJECT_MOBILEwa ||
- type == OBJECT_MOBILEwc ||
- type == OBJECT_MOBILEws ||
- type == OBJECT_MOBILEwi ||
- type == OBJECT_MOBILEwt )
+ if (type == OBJECT_MOBILEwa ||
+ type == OBJECT_MOBILEwc ||
+ type == OBJECT_MOBILEws ||
+ type == OBJECT_MOBILEwi ||
+ type == OBJECT_MOBILEwt)
{
// Creates the right-back wheel.
rank = m_engine->CreateObject();
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(6, rank);
m_object->SetObjectParent(6, 0);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "lem2w.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("lem2w.mod", false, rank);
m_object->SetPosition(6, Math::Vector(-3.0f, 1.0f, -3.0f));
// Creates the left-back wheel.
@@ -373,8 +357,7 @@ bool CMotionVehicle::Create(Math::Vector pos, float angle, ObjectType type,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(7, rank);
m_object->SetObjectParent(7, 0);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "lem2w.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("lem2w.mod", false, rank);
m_object->SetPosition(7, Math::Vector(-3.0f, 1.0f, 3.0f));
m_object->SetAngleY(7, Math::PI);
@@ -383,8 +366,7 @@ bool CMotionVehicle::Create(Math::Vector pos, float angle, ObjectType type,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(8, rank);
m_object->SetObjectParent(8, 0);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "lem2w.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("lem2w.mod", false, rank);
m_object->SetPosition(8, Math::Vector(2.0f, 1.0f, -3.0f));
// Creates the left-front wheel.
@@ -392,21 +374,19 @@ bool CMotionVehicle::Create(Math::Vector pos, float angle, ObjectType type,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(9, rank);
m_object->SetObjectParent(9, 0);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "lem2w.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("lem2w.mod", false, rank);
m_object->SetPosition(9, Math::Vector(2.0f, 1.0f, 3.0f));
m_object->SetAngleY(9, Math::PI);
}
- if ( type == OBJECT_MOBILEtg )
+ if (type == OBJECT_MOBILEtg)
{
// Creates the right-back wheel.
rank = m_engine->CreateObject();
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(6, rank);
m_object->SetObjectParent(6, 0);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "lem2w.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("lem2w.mod", false, rank);
m_object->SetPosition(6, Math::Vector(-2.0f, 1.0f, -3.0f));
// Creates the left-back wheel.
@@ -414,8 +394,7 @@ bool CMotionVehicle::Create(Math::Vector pos, float angle, ObjectType type,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(7, rank);
m_object->SetObjectParent(7, 0);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "lem2w.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("lem2w.mod", false, rank);
m_object->SetPosition(7, Math::Vector(-2.0f, 1.0f, 3.0f));
m_object->SetAngleY(7, Math::PI);
@@ -424,8 +403,7 @@ bool CMotionVehicle::Create(Math::Vector pos, float angle, ObjectType type,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(8, rank);
m_object->SetObjectParent(8, 0);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "lem2w.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("lem2w.mod", false, rank);
m_object->SetPosition(8, Math::Vector(3.0f, 1.0f, -3.0f));
// Creates the left-front wheel.
@@ -433,24 +411,22 @@ bool CMotionVehicle::Create(Math::Vector pos, float angle, ObjectType type,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(9, rank);
m_object->SetObjectParent(9, 0);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "lem2w.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("lem2w.mod", false, rank);
m_object->SetPosition(9, Math::Vector(3.0f, 1.0f, 3.0f));
m_object->SetAngleY(9, Math::PI);
}
- if ( type == OBJECT_MOBILEta ||
- type == OBJECT_MOBILEtc ||
- type == OBJECT_MOBILEti ||
- type == OBJECT_MOBILEts ) // caterpillars?
+ if (type == OBJECT_MOBILEta ||
+ type == OBJECT_MOBILEtc ||
+ type == OBJECT_MOBILEti ||
+ type == OBJECT_MOBILEts) // caterpillars?
{
// Creates the right caterpillar.
rank = m_engine->CreateObject();
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(6, rank);
m_object->SetObjectParent(6, 0);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "lem2t.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelCopy("lem2t.mod", false, rank);
m_object->SetPosition(6, Math::Vector(0.0f, 2.0f, -3.0f));
// Creates the left caterpillar.
@@ -458,23 +434,21 @@ bool CMotionVehicle::Create(Math::Vector pos, float angle, ObjectType type,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(7, rank);
m_object->SetObjectParent(7, 0);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "lem3t.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelCopy("lem3t.mod", false, rank);
m_object->SetPosition(7, Math::Vector(0.0f, 2.0f, 3.0f));
}
- if ( type == OBJECT_MOBILErt ||
- type == OBJECT_MOBILErc ||
- type == OBJECT_MOBILErr ||
- type == OBJECT_MOBILErs ) // large caterpillars?
+ if (type == OBJECT_MOBILErt ||
+ type == OBJECT_MOBILErc ||
+ type == OBJECT_MOBILErr ||
+ type == OBJECT_MOBILErs) // large caterpillars?
{
// Creates the right caterpillar.
rank = m_engine->CreateObject();
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(6, rank);
m_object->SetObjectParent(6, 0);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "roller2.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelCopy("roller2.mod", false, rank);
m_object->SetPosition(6, Math::Vector(0.0f, 2.0f, -3.0f));
// Creates the left caterpillar.
@@ -482,20 +456,18 @@ bool CMotionVehicle::Create(Math::Vector pos, float angle, ObjectType type,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(7, rank);
m_object->SetObjectParent(7, 0);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "roller3.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelCopy("roller3.mod", false, rank);
m_object->SetPosition(7, Math::Vector(0.0f, 2.0f, 3.0f));
}
- if ( type == OBJECT_MOBILEsa ) // underwater caterpillars?
+ if (type == OBJECT_MOBILEsa) // underwater caterpillars?
{
// Creates the right caterpillar.
rank = m_engine->CreateObject();
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(6, rank);
m_object->SetObjectParent(6, 0);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "subm4.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelCopy("subm4.mod", false, rank);
m_object->SetPosition(6, Math::Vector(0.0f, 1.0f, -3.0f));
// Creates the left caterpillar.
@@ -503,20 +475,18 @@ bool CMotionVehicle::Create(Math::Vector pos, float angle, ObjectType type,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(7, rank);
m_object->SetObjectParent(7, 0);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "subm5.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelCopy("subm5.mod", false, rank);
m_object->SetPosition(7, Math::Vector(0.0f, 1.0f, 3.0f));
}
- if ( type == OBJECT_MOBILEdr ) // caterpillars?
+ if (type == OBJECT_MOBILEdr) // caterpillars?
{
// Creates the right caterpillar.
rank = m_engine->CreateObject();
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(6, rank);
m_object->SetObjectParent(6, 0);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "drawer2.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelCopy("drawer2.mod", false, rank);
m_object->SetPosition(6, Math::Vector(0.0f, 1.0f, -3.0f));
// Creates the left caterpillar.
@@ -524,24 +494,22 @@ bool CMotionVehicle::Create(Math::Vector pos, float angle, ObjectType type,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(7, rank);
m_object->SetObjectParent(7, 0);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "drawer3.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelCopy("drawer3.mod", false, rank);
m_object->SetPosition(7, Math::Vector(0.0f, 1.0f, 3.0f));
}
- if ( type == OBJECT_MOBILEfa ||
- type == OBJECT_MOBILEfc ||
- type == OBJECT_MOBILEfs ||
- type == OBJECT_MOBILEfi ||
- type == OBJECT_MOBILEft ) // flying?
+ if (type == OBJECT_MOBILEfa ||
+ type == OBJECT_MOBILEfc ||
+ type == OBJECT_MOBILEfs ||
+ type == OBJECT_MOBILEfi ||
+ type == OBJECT_MOBILEft) // flying?
{
// Creates the front foot.
rank = m_engine->CreateObject();
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(6, rank);
m_object->SetObjectParent(6, 0);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "lem2f.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("lem2f.mod", false, rank);
m_object->SetPosition(6, Math::Vector(1.7f, 3.0f, 0.0f));
// Creates the right-back foot.
@@ -549,8 +517,7 @@ bool CMotionVehicle::Create(Math::Vector pos, float angle, ObjectType type,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(7, rank);
m_object->SetObjectParent(7, 0);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "lem2f.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("lem2f.mod", false, rank);
m_object->SetPosition(7, Math::Vector(-1.8f, 3.0f, -1.5f));
m_object->SetAngleY(7, 120.0f*Math::PI/180.0f);
@@ -559,16 +526,15 @@ bool CMotionVehicle::Create(Math::Vector pos, float angle, ObjectType type,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(8, rank);
m_object->SetObjectParent(8, 0);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "lem2f.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("lem2f.mod", false, rank);
m_object->SetPosition(8, Math::Vector(-1.8f, 3.0f, 1.5f));
m_object->SetAngleY(8, -120.0f*Math::PI/180.0f);
}
- if ( type == OBJECT_MOBILEia ||
- type == OBJECT_MOBILEic ||
- type == OBJECT_MOBILEis ||
- type == OBJECT_MOBILEii ) // insect legs?
+ if (type == OBJECT_MOBILEia ||
+ type == OBJECT_MOBILEic ||
+ type == OBJECT_MOBILEis ||
+ type == OBJECT_MOBILEii) // insect legs?
{
float table[] =
{
@@ -590,8 +556,7 @@ bool CMotionVehicle::Create(Math::Vector pos, float angle, ObjectType type,
{
for ( j=0 ; j<3 ; j++ )
{
- std::string baseName = m_app->GetDataFilePath(DIR_MODEL, "ant%d.mod");
- sprintf(name, baseName.c_str(), j+4); // 4..6
+ sprintf(name, "ant%d.mod", j+4); // 4..6
// Creates the right leg.
rank = m_engine->CreateObject();
@@ -600,8 +565,7 @@ bool CMotionVehicle::Create(Math::Vector pos, float angle, ObjectType type,
if ( j == 0 ) parent = 0;
else parent = 6+i*3+j-1;
m_object->SetObjectParent(6+i*3+j, parent);
- pModFile->ReadModel(name);
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference(name, false, rank);
pos.x = table[i*9+j*3+0];
pos.y = table[i*9+j*3+1];
pos.z = table[i*9+j*3+2];
@@ -614,9 +578,7 @@ bool CMotionVehicle::Create(Math::Vector pos, float angle, ObjectType type,
if ( j == 0 ) parent = 0;
else parent = 15+i*3+j-1;
m_object->SetObjectParent(15+i*3+j, parent);
- pModFile->ReadModel(name);
- pModFile->Mirror();
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference(name, true, rank);
pos.x = table[i*9+j*3+0];
pos.y = table[i*9+j*3+1];
pos.z = -table[i*9+j*3+2];
@@ -625,15 +587,14 @@ bool CMotionVehicle::Create(Math::Vector pos, float angle, ObjectType type,
}
}
- if ( type == OBJECT_MOBILErt )
+ if (type == OBJECT_MOBILErt)
{
// Creates the holder.
rank = m_engine->CreateObject();
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(1, rank);
m_object->SetObjectParent(1, 0);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "roller2t.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("roller2t.mod", false, rank);
m_object->SetPosition(1, Math::Vector(0.0f, 0.0f, 0.0f));
m_object->SetAngleZ(1, 0.0f);
@@ -642,21 +603,19 @@ bool CMotionVehicle::Create(Math::Vector pos, float angle, ObjectType type,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(2, rank);
m_object->SetObjectParent(2, 0);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "roller3t.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("roller3t.mod", false, rank);
m_object->SetPosition(2, Math::Vector(9.0f, 4.0f, 0.0f));
m_object->SetAngleZ(2, 0.0f);
}
- if ( type == OBJECT_MOBILErc )
+ if (type == OBJECT_MOBILErc)
{
// Creates the holder.
rank = m_engine->CreateObject();
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(1, rank);
m_object->SetObjectParent(1, 0);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "roller2c.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("roller2c.mod", false, rank);
m_object->SetPosition(1, Math::Vector(3.0f, 4.6f, 0.0f));
m_object->SetAngleZ(1, Math::PI/8.0f);
@@ -665,21 +624,19 @@ bool CMotionVehicle::Create(Math::Vector pos, float angle, ObjectType type,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(2, rank);
m_object->SetObjectParent(2, 0);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "roller3p.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("roller3p.mod", false, rank);
m_object->SetPosition(2, Math::Vector(7.0f, 6.5f, 0.0f));
m_object->SetAngleZ(2, 0.0f);
}
- if ( type == OBJECT_MOBILErr )
+ if (type == OBJECT_MOBILErr)
{
// Creates the holder.
rank = m_engine->CreateObject();
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(1, rank);
m_object->SetObjectParent(1, 0);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "recover1.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("recover1.mod", false, rank);
m_object->SetPosition(1, Math::Vector(2.0f, 5.0f, 0.0f));
// Creates the right arm.
@@ -687,8 +644,7 @@ bool CMotionVehicle::Create(Math::Vector pos, float angle, ObjectType type,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(2, rank);
m_object->SetObjectParent(2, 1);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "recover2.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("recover2.mod", false, rank);
m_object->SetPosition(2, Math::Vector(0.1f, 0.0f, -5.0f));
m_object->SetAngleZ(2, 126.0f*Math::PI/180.0f);
@@ -697,8 +653,7 @@ bool CMotionVehicle::Create(Math::Vector pos, float angle, ObjectType type,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(3, rank);
m_object->SetObjectParent(3, 2);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "recover3.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("recover3.mod", false, rank);
m_object->SetPosition(3, Math::Vector(5.0f, 0.0f, -0.5f));
m_object->SetAngleZ(3, -144.0f*Math::PI/180.0f);
@@ -707,9 +662,7 @@ bool CMotionVehicle::Create(Math::Vector pos, float angle, ObjectType type,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(4, rank);
m_object->SetObjectParent(4, 1);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "recover2.mod"));
- pModFile->Mirror();
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("recover2.mod", true, rank);
m_object->SetPosition(4, Math::Vector(0.1f, 0.0f, 5.0f));
m_object->SetAngleZ(4, 126.0f*Math::PI/180.0f);
@@ -718,22 +671,19 @@ bool CMotionVehicle::Create(Math::Vector pos, float angle, ObjectType type,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(5, rank);
m_object->SetObjectParent(5, 4);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "recover3.mod"));
- pModFile->Mirror();
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("recover3.mod", true, rank);
m_object->SetPosition(5, Math::Vector(5.0f, 0.0f, 0.5f));
m_object->SetAngleZ(5, -144.0f*Math::PI/180.0f);
}
- if ( type == OBJECT_MOBILErs )
+ if (type == OBJECT_MOBILErs)
{
// Creates the holder.
rank = m_engine->CreateObject();
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(1, rank);
m_object->SetObjectParent(1, 0);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "roller2s.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("roller2s.mod", false, rank);
m_object->SetPosition(1, Math::Vector(0.0f, 0.0f, 0.0f));
m_object->SetAngleZ(1, 0.0f);
@@ -742,8 +692,7 @@ bool CMotionVehicle::Create(Math::Vector pos, float angle, ObjectType type,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(2, rank);
m_object->SetObjectParent(2, 1);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "roller3s.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("roller3s.mod", false, rank);
m_object->SetPosition(2, Math::Vector(7.0f, 4.5f, 0.0f));
m_object->SetAngleZ(2, 0.0f);
@@ -752,21 +701,19 @@ bool CMotionVehicle::Create(Math::Vector pos, float angle, ObjectType type,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(3, rank);
m_object->SetObjectParent(3, 2);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "roller4s.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("roller4s.mod", false, rank);
m_object->SetPosition(3, Math::Vector(0.0f, 1.0f, 0.0f));
m_object->SetAngleZ(3, 0.0f);
}
- if ( type == OBJECT_MOBILEsa )
+ if (type == OBJECT_MOBILEsa)
{
// Creates the holder.
rank = m_engine->CreateObject();
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(1, rank);
m_object->SetObjectParent(1, 0);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "subm2.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("subm2.mod", false, rank);
m_object->SetPosition(1, Math::Vector(4.2f, 3.0f, 0.0f));
// Creates the right tong.
@@ -774,8 +721,7 @@ bool CMotionVehicle::Create(Math::Vector pos, float angle, ObjectType type,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(2, rank);
m_object->SetObjectParent(2, 1);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "subm3.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("subm3.mod", false, rank);
m_object->SetPosition(2, Math::Vector(0.5f, 0.0f, -1.5f));
// Creates the left tong.
@@ -783,21 +729,18 @@ bool CMotionVehicle::Create(Math::Vector pos, float angle, ObjectType type,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(3, rank);
m_object->SetObjectParent(3, 1);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "subm3.mod"));
- pModFile->Mirror();
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("subm3.mod", true, rank);
m_object->SetPosition(3, Math::Vector(0.5f, 0.0f, 1.5f));
}
- if ( type == OBJECT_MOBILEdr )
+ if (type == OBJECT_MOBILEdr)
{
// Creates the carousel.
rank = m_engine->CreateObject();
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(1, rank);
m_object->SetObjectParent(1, 0);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "drawer4.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("drawer4.mod", false, rank);
m_object->SetPosition(1, Math::Vector(-3.0f, 3.0f, 0.0f));
// Creates the key.
@@ -807,8 +750,7 @@ bool CMotionVehicle::Create(Math::Vector pos, float angle, ObjectType type,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(2, rank);
m_object->SetObjectParent(2, 0);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "drawer5.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("drawer5.mod", false, rank);
m_posKey = Math::Vector(3.0f, 5.7f, 0.0f);
m_object->SetPosition(2, m_posKey);
m_object->SetAngleY(2, 90.0f*Math::PI/180.0f);
@@ -821,16 +763,14 @@ bool CMotionVehicle::Create(Math::Vector pos, float angle, ObjectType type,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(10+i, rank);
m_object->SetObjectParent(10+i, 1);
- std::string baseName = m_app->GetDataFilePath(DIR_MODEL, "drawer%d.mod");
- sprintf(name, baseName.c_str(), 10+i);
- pModFile->ReadModel(name);
- pModFile->CreateEngineObject(rank);
+ sprintf(name, "drawer%d.mod", 10+i);
+ modelManager->AddModelReference(name, false, rank);
m_object->SetPosition(10+i, Math::Vector(0.0f, 0.0f, 0.0f));
m_object->SetAngleY(10+i, 45.0f*Math::PI/180.0f*i);
}
}
- if ( type == OBJECT_MOBILEwt )
+ if (type == OBJECT_MOBILEwt)
{
// Creates the key.
if ( m_object->GetToy() )
@@ -839,23 +779,21 @@ bool CMotionVehicle::Create(Math::Vector pos, float angle, ObjectType type,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(2, rank);
m_object->SetObjectParent(2, 0);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "drawer5.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("drawer5.mod", false, rank);
m_posKey = Math::Vector(0.2f, 4.1f, 0.0f);
m_object->SetPosition(2, m_posKey);
m_object->SetAngleY(2, 90.0f*Math::PI/180.0f);
}
}
- if ( type == OBJECT_APOLLO2 )
+ if (type == OBJECT_APOLLO2)
{
// Creates the accessories.
rank = m_engine->CreateObject();
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(1, rank);
m_object->SetObjectParent(1, 0);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "apolloj2.mod")); // antenna
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("apolloj2.mod", false, rank); // antenna
m_object->SetPosition(1, Math::Vector(5.5f, 8.8f, 2.0f));
m_object->SetAngleY(1, -120.0f*Math::PI/180.0f);
m_object->SetAngleZ(1, 45.0f*Math::PI/180.0f);
@@ -864,8 +802,7 @@ bool CMotionVehicle::Create(Math::Vector pos, float angle, ObjectType type,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(2, rank);
m_object->SetObjectParent(2, 0);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "apolloj3.mod")); // camera
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("apolloj3.mod", false, rank); // camera
m_object->SetPosition(2, Math::Vector(5.5f, 2.8f, -2.0f));
m_object->SetAngleY(2, 30.0f*Math::PI/180.0f);
@@ -874,32 +811,28 @@ bool CMotionVehicle::Create(Math::Vector pos, float angle, ObjectType type,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(6, rank);
m_object->SetObjectParent(6, 0);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "apolloj4.mod")); // wheel
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("apolloj4.mod", false, rank); // wheel
m_object->SetPosition(6, Math::Vector(-5.75f, 1.65f, -5.0f));
rank = m_engine->CreateObject();
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(7, rank);
m_object->SetObjectParent(7, 0);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "apolloj4.mod")); // wheel
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("apolloj4.mod", false, rank); // wheel
m_object->SetPosition(7, Math::Vector(-5.75f, 1.65f, 5.0f));
rank = m_engine->CreateObject();
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(8, rank);
m_object->SetObjectParent(8, 0);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "apolloj4.mod")); // wheel
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("apolloj4.mod", false, rank); // wheel
m_object->SetPosition(8, Math::Vector(5.75f, 1.65f, -5.0f));
rank = m_engine->CreateObject();
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(9, rank);
m_object->SetObjectParent(9, 0);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "apolloj4.mod")); // wheel
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("apolloj4.mod", false, rank); // wheel
m_object->SetPosition(9, Math::Vector(5.75f, 1.65f, 5.00f));
// Creates mud guards.
@@ -907,56 +840,51 @@ bool CMotionVehicle::Create(Math::Vector pos, float angle, ObjectType type,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(10, rank);
m_object->SetObjectParent(10, 0);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "apolloj6.mod")); // wheel
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("apolloj6.mod", false, rank); // wheel
m_object->SetPosition(10, Math::Vector(-5.75f, 1.65f, -5.0f));
rank = m_engine->CreateObject();
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(11, rank);
m_object->SetObjectParent(11, 0);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "apolloj6.mod")); // wheel
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("apolloj6.mod", false, rank); // wheel
m_object->SetPosition(11, Math::Vector(-5.75f, 1.65f, 5.0f));
rank = m_engine->CreateObject();
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(12, rank);
m_object->SetObjectParent(12, 0);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "apolloj5.mod")); // wheel
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("apolloj5.mod", false, rank); // wheel
m_object->SetPosition(12, Math::Vector(5.75f, 1.65f, -5.0f));
rank = m_engine->CreateObject();
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(13, rank);
m_object->SetObjectParent(13, 0);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "apolloj5.mod")); // wheel
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("apolloj5.mod", false, rank); // wheel
m_object->SetPosition(13, Math::Vector(5.75f, 1.65f, 5.00f));
}
-#if 1
- if ( type == OBJECT_MOBILErt ||
- type == OBJECT_MOBILErc ||
- type == OBJECT_MOBILErr ||
- type == OBJECT_MOBILErs )
+ if (type == OBJECT_MOBILErt ||
+ type == OBJECT_MOBILErc ||
+ type == OBJECT_MOBILErr ||
+ type == OBJECT_MOBILErs)
{
m_object->CreateShadowCircle(6.0f, 1.0f);
}
- else if ( type == OBJECT_MOBILEta ||
- type == OBJECT_MOBILEtc ||
- type == OBJECT_MOBILEti ||
- type == OBJECT_MOBILEts ||
- type == OBJECT_MOBILEsa )
+ else if (type == OBJECT_MOBILEta ||
+ type == OBJECT_MOBILEtc ||
+ type == OBJECT_MOBILEti ||
+ type == OBJECT_MOBILEts ||
+ type == OBJECT_MOBILEsa)
{
m_object->CreateShadowCircle(5.0f, 1.0f);
}
- else if ( type == OBJECT_MOBILEdr )
+ else if (type == OBJECT_MOBILEdr)
{
m_object->CreateShadowCircle(4.5f, 1.0f);
}
- else if ( type == OBJECT_APOLLO2 )
+ else if (type == OBJECT_APOLLO2)
{
m_object->CreateShadowCircle(7.0f, 0.8f);
}
@@ -964,50 +892,12 @@ bool CMotionVehicle::Create(Math::Vector pos, float angle, ObjectType type,
{
m_object->CreateShadowCircle(4.0f, 1.0f);
}
-#else
- if ( type == OBJECT_MOBILErt ||
- type == OBJECT_MOBILErc ||
- type == OBJECT_MOBILErr ||
- type == OBJECT_MOBILErs )
- {
- m_object->CreateShadowCircle(6.0f, 1.0f, D3DSHADOWTANK);
- }
- else if ( type == OBJECT_MOBILEta ||
- type == OBJECT_MOBILEtc ||
- type == OBJECT_MOBILEti ||
- type == OBJECT_MOBILEts )
- {
- m_object->CreateShadowCircle(4.0f, 1.0f, D3DSHADOWTANK);
- }
- else if ( type == OBJECT_MOBILEfa ||
- type == OBJECT_MOBILEfc ||
- type == OBJECT_MOBILEfi ||
- type == OBJECT_MOBILEfs )
- {
- m_object->CreateShadowCircle(4.0f, 1.0f, D3DSHADOWFLY);
- }
- else if ( type == OBJECT_MOBILEwa ||
- type == OBJECT_MOBILEwc ||
- type == OBJECT_MOBILEwi ||
- type == OBJECT_MOBILEws )
- {
- m_object->CreateShadowCircle(4.0f, 1.0f, D3DSHADOWWHEEL);
- }
- else if ( type == OBJECT_APOLLO2 )
- {
- m_object->CreateShadowCircle(6.0f, 0.8f);
- }
- else
- {
- m_object->CreateShadowCircle(4.0f, 1.0f, D3DSHADOWNORM);
- }
-#endif
- if ( type == OBJECT_MOBILEfa ||
- type == OBJECT_MOBILEfc ||
- type == OBJECT_MOBILEfi ||
- type == OBJECT_MOBILEfs ||
- type == OBJECT_MOBILEft ) // flying?
+ if (type == OBJECT_MOBILEfa ||
+ type == OBJECT_MOBILEfc ||
+ type == OBJECT_MOBILEfi ||
+ type == OBJECT_MOBILEfs ||
+ type == OBJECT_MOBILEft) // flying?
{
//? color.r = 0.5f-1.0f;
//? color.g = 0.2f-1.0f;
@@ -1025,9 +915,9 @@ bool CMotionVehicle::Create(Math::Vector pos, float angle, ObjectType type,
CreatePhysics(type);
m_object->SetFloorHeight(0.0f);
- if ( power > 0.0f &&
- type != OBJECT_MOBILEdr &&
- type != OBJECT_APOLLO2 )
+ if (power > 0.0f &&
+ type != OBJECT_MOBILEdr &&
+ type != OBJECT_APOLLO2)
{
color.r = 1.0f;
color.g = 1.0f;
@@ -1043,9 +933,8 @@ bool CMotionVehicle::Create(Math::Vector pos, float angle, ObjectType type,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX);
pPower->SetObjectRank(0, rank);
- if ( power <= 1.0f ) pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "power.mod"));
- else pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "atomic.mod"));
- pModFile->CreateEngineObject(rank);
+ if ( power <= 1.0f ) modelManager->AddModelCopy("power.mod", false, rank);
+ else modelManager->AddModelCopy("atomic.mod", false, rank);
pPower->SetPosition(0, m_object->GetCharacter()->posPower);
pPower->CreateCrashSphere(Math::Vector(0.0f, 1.0f, 0.0f), 1.0f, SOUND_BOUMm, 0.45f);
@@ -1063,7 +952,6 @@ bool CMotionVehicle::Create(Math::Vector pos, float angle, ObjectType type,
m_engine->LoadAllTextures();
- delete pModFile;
return true;
}
diff --git a/src/object/motion/motionworm.cpp b/src/object/motion/motionworm.cpp
index 2401ebd..f32765d 100644
--- a/src/object/motion/motionworm.cpp
+++ b/src/object/motion/motionworm.cpp
@@ -19,7 +19,7 @@
#include "app/app.h"
-#include "graphics/engine/modelfile.h"
+#include "graphics/engine/modelmanager.h"
#include "graphics/engine/particle.h"
#include "graphics/engine/terrain.h"
@@ -81,13 +81,10 @@ void CMotionWorm::DeleteObject(bool bAll)
bool CMotionWorm::Create(Math::Vector pos, float angle, ObjectType type,
float power)
{
- Gfx::CModelFile* pModFile;
int rank, i;
float px;
-// if ( m_engine->GetRestCreate() < 2+WORM_PART+1 ) return false;
-
- pModFile = new Gfx::CModelFile(m_iMan);
+ Gfx::CModelManager* modelManager = Gfx::CModelManager::GetInstancePointer();
m_object->SetType(type);
@@ -95,8 +92,7 @@ bool CMotionWorm::Create(Math::Vector pos, float angle, ObjectType type,
rank = m_engine->CreateObject();
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_VEHICULE); // this is a moving object
m_object->SetObjectRank(0, rank);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "worm0.mod")); // there is no purpose!
- pModFile->CreateEngineObject(rank);
+ // This is an "empty" object, without triangles
m_object->SetPosition(0, pos);
m_object->SetAngleY(0, angle);
@@ -111,8 +107,7 @@ bool CMotionWorm::Create(Math::Vector pos, float angle, ObjectType type,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(1, rank);
m_object->SetObjectParent(1, 0);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "worm1.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("worm1.mod", false, rank);
m_object->SetPosition(1, Math::Vector(px, 0.0f, 0.0f));
px -= 1.0f;
@@ -123,8 +118,7 @@ bool CMotionWorm::Create(Math::Vector pos, float angle, ObjectType type,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(2+i, rank);
m_object->SetObjectParent(2+i, 0);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "worm2.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("worm2.mod", false, rank);
m_object->SetPosition(2+i, Math::Vector(px, 0.0f, 0.0f));
px -= 1.0f;
}
@@ -134,8 +128,7 @@ bool CMotionWorm::Create(Math::Vector pos, float angle, ObjectType type,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(2+WORM_PART, rank);
m_object->SetObjectParent(2+WORM_PART, 0);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "worm3.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("worm3.mod", false, rank);
m_object->SetPosition(2+WORM_PART, Math::Vector(px, 0.0f, 0.0f));
m_object->CreateShadowCircle(0.0f, 1.0f, Gfx::ENG_SHADOW_WORM);
@@ -148,7 +141,6 @@ bool CMotionWorm::Create(Math::Vector pos, float angle, ObjectType type,
m_engine->LoadAllTextures();
- delete pModFile;
return true;
}
diff --git a/src/object/object.cpp b/src/object/object.cpp
index 2eade93..afa7815 100644
--- a/src/object/object.cpp
+++ b/src/object/object.cpp
@@ -27,7 +27,7 @@
#include "graphics/engine/lightman.h"
#include "graphics/engine/lightning.h"
-#include "graphics/engine/modelfile.h"
+#include "graphics/engine/modelmanager.h"
#include "graphics/engine/particle.h"
#include "graphics/engine/pyro.h"
#include "graphics/engine/terrain.h"
@@ -2351,11 +2351,10 @@ bool CObject::CreateShadowCircle(float radius, float intensity,
bool CObject::CreateBuilding(Math::Vector pos, float angle, float height,
ObjectType type, float power)
{
- Gfx::CModelFile* pModFile;
Math::Point p;
int rank, i;
- pModFile = new Gfx::CModelFile(m_iMan);
+ Gfx::CModelManager* modelManager = Gfx::CModelManager::GetInstancePointer();
SetType(type);
@@ -2365,8 +2364,7 @@ bool CObject::CreateBuilding(Math::Vector pos, float angle, float height,
if ( m_type == OBJECT_PORTICO )
{
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "portico1.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("portico1.mod", false, rank);
SetPosition(0, pos);
SetAngleY(0, angle);
SetFloorHeight(0.0f);
@@ -2375,16 +2373,14 @@ bool CObject::CreateBuilding(Math::Vector pos, float angle, float height,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
SetObjectRank(1, rank);
SetObjectParent(1, 0);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "portico2.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("portico2.mod", false, rank);
SetPosition(1, Math::Vector(0.0f, 67.0f, 0.0f));
rank = m_engine->CreateObject();
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
SetObjectRank(2, rank);
SetObjectParent(2, 1);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "portico3.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("portico3.mod", false, rank);
SetPosition(2, Math::Vector(0.0f, 0.0f, -33.0f));
SetAngleY(2, 45.0f*Math::PI/180.0f);
@@ -2392,8 +2388,7 @@ bool CObject::CreateBuilding(Math::Vector pos, float angle, float height,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
SetObjectRank(3, rank);
SetObjectParent(3, 2);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "portico4.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("portico4.mod", false, rank);
SetPosition(3, Math::Vector(50.0f, 0.0f, 0.0f));
SetAngleY(3, -60.0f*Math::PI/180.0f);
@@ -2401,8 +2396,7 @@ bool CObject::CreateBuilding(Math::Vector pos, float angle, float height,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
SetObjectRank(4, rank);
SetObjectParent(4, 3);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "portico5.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("portico5.mod", false, rank);
SetPosition(4, Math::Vector(35.0f, 0.0f, 0.0f));
SetAngleY(4, -55.0f*Math::PI/180.0f);
@@ -2410,8 +2404,7 @@ bool CObject::CreateBuilding(Math::Vector pos, float angle, float height,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
SetObjectRank(5, rank);
SetObjectParent(5, 1);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "portico3.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("portico3.mod", false, rank);
SetPosition(5, Math::Vector(0.0f, 0.0f, 33.0f));
SetAngleY(5, -45.0f*Math::PI/180.0f);
@@ -2419,8 +2412,7 @@ bool CObject::CreateBuilding(Math::Vector pos, float angle, float height,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
SetObjectRank(6, rank);
SetObjectParent(6, 5);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "portico4.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("portico4.mod", false, rank);
SetPosition(6, Math::Vector(50.0f, 0.0f, 0.0f));
SetAngleY(6, 60.0f*Math::PI/180.0f);
@@ -2428,8 +2420,7 @@ bool CObject::CreateBuilding(Math::Vector pos, float angle, float height,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
SetObjectRank(7, rank);
SetObjectParent(7, 6);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "portico5.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("portico5.mod", false, rank);
SetPosition(7, Math::Vector(35.0f, 0.0f, 0.0f));
SetAngleY(7, 55.0f*Math::PI/180.0f);
@@ -2437,8 +2428,7 @@ bool CObject::CreateBuilding(Math::Vector pos, float angle, float height,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
SetObjectRank(8, rank);
SetObjectParent(8, 0);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "portico6.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("portico6.mod", false, rank);
SetPosition(8, Math::Vector(-35.0f, 50.0f, -35.0f));
SetAngleY(8, -Math::PI/2.0f);
SetZoom(8, 2.0f);
@@ -2447,16 +2437,14 @@ bool CObject::CreateBuilding(Math::Vector pos, float angle, float height,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
SetObjectRank(9, rank);
SetObjectParent(9, 8);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "portico7.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("portico7.mod", false, rank);
SetPosition(9, Math::Vector(0.0f, 4.5f, 1.9f));
rank = m_engine->CreateObject();
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
SetObjectRank(10, rank);
SetObjectParent(10, 0);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "portico6.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("portico6.mod", false, rank);
SetPosition(10, Math::Vector(-35.0f, 50.0f, 35.0f));
SetAngleY(10, -Math::PI/2.0f);
SetZoom(10, 2.0f);
@@ -2465,8 +2453,7 @@ bool CObject::CreateBuilding(Math::Vector pos, float angle, float height,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
SetObjectRank(11, rank);
SetObjectParent(11, 10);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "portico7.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("portico7.mod", false, rank);
SetPosition(11, Math::Vector(0.0f, 4.5f, 1.9f));
CreateCrashSphere(Math::Vector( 0.0f, 28.0f, 0.0f), 45.5f, SOUND_BOUMm, 0.45f);
@@ -2487,8 +2474,7 @@ bool CObject::CreateBuilding(Math::Vector pos, float angle, float height,
if ( m_type == OBJECT_BASE )
{
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "base1.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("base1.mod", false, rank);
SetPosition(0, pos);
SetAngleY(0, angle);
SetFloorHeight(0.0f);
@@ -2499,8 +2485,7 @@ bool CObject::CreateBuilding(Math::Vector pos, float angle, float height,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
SetObjectRank(1+i, rank);
SetObjectParent(1+i, 0);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "base2.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("base2.mod", false, rank);
p = Math::RotatePoint(-Math::PI/4.0f*i, 27.8f);
SetPosition(1+i, Math::Vector(p.x, 30.0f, p.y));
SetAngleY(1+i, Math::PI/4.0f*i);
@@ -2510,17 +2495,14 @@ bool CObject::CreateBuilding(Math::Vector pos, float angle, float height,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
SetObjectRank(10+i, rank);
SetObjectParent(10+i, 1+i);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "base4.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("base4.mod", false, rank);
SetPosition(10+i, Math::Vector(23.5f, 0.0f, 7.0f));
rank = m_engine->CreateObject();
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
SetObjectRank(18+i, rank);
SetObjectParent(18+i, 1+i);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "base4.mod"));
- pModFile->Mirror();
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("base4.mod", true, rank);
SetPosition(18+i, Math::Vector(23.5f, 0.0f, -7.0f));
}
@@ -2528,8 +2510,7 @@ bool CObject::CreateBuilding(Math::Vector pos, float angle, float height,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
SetObjectRank(9, rank);
SetObjectParent(9, 0);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "base3.mod")); // central pillar
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("base3.mod", false, rank); // central pillar
CreateCrashSphere(Math::Vector( 0.0f, 33.0f, 0.0f), 2.5f, SOUND_BOUMm, 0.45f);
CreateCrashSphere(Math::Vector( 0.0f, 39.0f, 0.0f), 2.5f, SOUND_BOUMm, 0.45f);
@@ -2559,8 +2540,7 @@ bool CObject::CreateBuilding(Math::Vector pos, float angle, float height,
if ( m_type == OBJECT_DERRICK )
{
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "derrick1.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("derrick1.mod", false, rank);
SetPosition(0, pos);
SetAngleY(0, angle);
SetFloorHeight(0.0f);
@@ -2569,8 +2549,7 @@ bool CObject::CreateBuilding(Math::Vector pos, float angle, float height,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
SetObjectRank(1, rank);
SetObjectParent(1, 0);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "derrick2.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("derrick2.mod", false, rank);
CreateCrashSphere(Math::Vector(0.0f, 0.0f, 0.0f), 6.0f, SOUND_BOUMm, 0.45f);
CreateCrashSphere(Math::Vector(0.0f, 10.0f, 0.0f), 5.0f, SOUND_BOUMm, 0.45f);
@@ -2584,8 +2563,7 @@ bool CObject::CreateBuilding(Math::Vector pos, float angle, float height,
if ( m_type == OBJECT_RESEARCH )
{
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "search1.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("search1.mod", false, rank);
SetPosition(0, pos);
SetAngleY(0, angle);
SetFloorHeight(0.0f);
@@ -2594,16 +2572,14 @@ bool CObject::CreateBuilding(Math::Vector pos, float angle, float height,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
SetObjectRank(1, rank);
SetObjectParent(1, 0);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "search2.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("search2.mod", false, rank);
SetPosition(1, Math::Vector(0.0f, 13.0f, 0.0f));
rank = m_engine->CreateObject();
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
SetObjectRank(2, rank);
SetObjectParent(2, 1);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "search3.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("search3.mod", false, rank);
SetPosition(2, Math::Vector(0.0f, 4.0f, 0.0f));
SetAngleZ(2, 35.0f*Math::PI/180.0f);
@@ -2619,8 +2595,7 @@ bool CObject::CreateBuilding(Math::Vector pos, float angle, float height,
if ( m_type == OBJECT_RADAR )
{
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "radar1.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("radar1.mod", false, rank);
SetPosition(0, pos);
SetAngleY(0, angle);
SetFloorHeight(0.0f);
@@ -2629,16 +2604,14 @@ bool CObject::CreateBuilding(Math::Vector pos, float angle, float height,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
SetObjectRank(1, rank);
SetObjectParent(1, 0);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "radar2.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("radar2.mod", false, rank);
SetPosition(1, Math::Vector(0.0f, 5.0f, 0.0f));
rank = m_engine->CreateObject();
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
SetObjectRank(2, rank);
SetObjectParent(2, 0);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "radar3.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("radar3.mod", false, rank);
SetPosition(2, Math::Vector(0.0f, 11.0f, 0.0f));
SetAngleY(2, -Math::PI/2.0f);
@@ -2646,8 +2619,7 @@ bool CObject::CreateBuilding(Math::Vector pos, float angle, float height,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
SetObjectRank(3, rank);
SetObjectParent(3, 2);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "radar4.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("radar4.mod", false, rank);
SetPosition(3, Math::Vector(0.0f, 4.5f, 1.9f));
CreateCrashSphere(Math::Vector(0.0f, 3.0f, 0.0f), 6.0f, SOUND_BOUMm, 0.45f);
@@ -2659,8 +2631,7 @@ bool CObject::CreateBuilding(Math::Vector pos, float angle, float height,
if ( m_type == OBJECT_INFO )
{
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "info1.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("info1.mod", false, rank);
SetPosition(0, pos);
SetAngleY(0, angle);
SetFloorHeight(0.0f);
@@ -2669,8 +2640,7 @@ bool CObject::CreateBuilding(Math::Vector pos, float angle, float height,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
SetObjectRank(1, rank);
SetObjectParent(1, 0);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "info2.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("info2.mod", false, rank);
SetPosition(1, Math::Vector(0.0f, 5.0f, 0.0f));
for ( i=0 ; i<3 ; i++ )
@@ -2679,16 +2649,14 @@ bool CObject::CreateBuilding(Math::Vector pos, float angle, float height,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
SetObjectRank(2+i*2, rank);
SetObjectParent(2+i*2, 1);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "info3.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("info3.mod", false, rank);
SetPosition(2+i*2, Math::Vector(0.0f, 4.5f, 0.0f));
rank = m_engine->CreateObject();
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
SetObjectRank(3+i*2, rank);
SetObjectParent(3+i*2, 2+i*2);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "radar4.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("radar4.mod", false, rank);
SetPosition(3+i*2, Math::Vector(0.0f, 0.0f, -4.0f));
SetAngleY(2+i*2, 2.0f*Math::PI/3.0f*i);
@@ -2703,8 +2671,7 @@ bool CObject::CreateBuilding(Math::Vector pos, float angle, float height,
if ( m_type == OBJECT_ENERGY )
{
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "energy.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("energy.mod", false, rank);
SetPosition(0, pos);
SetAngleY(0, angle);
SetFloorHeight(0.0f);
@@ -2722,8 +2689,7 @@ bool CObject::CreateBuilding(Math::Vector pos, float angle, float height,
if ( m_type == OBJECT_LABO )
{
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "labo1.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("labo1.mod", false, rank);
SetPosition(0, pos);
SetAngleY(0, angle);
SetFloorHeight(0.0f);
@@ -2732,8 +2698,7 @@ bool CObject::CreateBuilding(Math::Vector pos, float angle, float height,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
SetObjectRank(1, rank);
SetObjectParent(1, 0);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "labo2.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("labo2.mod", false, rank);
SetPosition(1, Math::Vector(-9.0f, 3.0f, 0.0f));
SetAngleZ(1, Math::PI/2.0f);
@@ -2741,16 +2706,14 @@ bool CObject::CreateBuilding(Math::Vector pos, float angle, float height,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
SetObjectRank(2, rank);
SetObjectParent(2, 1);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "labo3.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("labo3.mod", false, rank);
SetPosition(2, Math::Vector(9.0f, -1.0f, 0.0f));
rank = m_engine->CreateObject();
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
SetObjectRank(3, rank);
SetObjectParent(3, 2);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "labo4.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("labo4.mod", false, rank);
SetPosition(3, Math::Vector(0.0f, 0.0f, 0.0f));
SetAngleZ(3, 80.0f*Math::PI/180.0f);
@@ -2758,8 +2721,7 @@ bool CObject::CreateBuilding(Math::Vector pos, float angle, float height,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
SetObjectRank(4, rank);
SetObjectParent(4, 2);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "labo4.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("labo4.mod", false, rank);
SetPosition(4, Math::Vector(0.0f, 0.0f, 0.0f));
SetAngleZ(4, 80.0f*Math::PI/180.0f);
SetAngleY(4, Math::PI*2.0f/3.0f);
@@ -2768,8 +2730,7 @@ bool CObject::CreateBuilding(Math::Vector pos, float angle, float height,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
SetObjectRank(5, rank);
SetObjectParent(5, 2);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "labo4.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("labo4.mod", false, rank);
SetPosition(5, Math::Vector(0.0f, 0.0f, 0.0f));
SetAngleZ(5, 80.0f*Math::PI/180.0f);
SetAngleY(5, -Math::PI*2.0f/3.0f);
@@ -2788,8 +2749,7 @@ bool CObject::CreateBuilding(Math::Vector pos, float angle, float height,
if ( m_type == OBJECT_FACTORY )
{
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "factory1.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("factory1.mod", false, rank);
SetPosition(0, pos);
SetAngleY(0, angle);
SetFloorHeight(0.0f);
@@ -2800,8 +2760,7 @@ bool CObject::CreateBuilding(Math::Vector pos, float angle, float height,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
SetObjectRank(1+i, rank);
SetObjectParent(1+i, 0);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "factory2.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("factory2.mod", false, rank);
SetPosition(1+i, Math::Vector(10.0f, 2.0f*i, 10.0f));
SetAngleZ(1+i, Math::PI/2.0f);
SetZoomZ(1+i, 0.30f);
@@ -2810,8 +2769,7 @@ bool CObject::CreateBuilding(Math::Vector pos, float angle, float height,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
SetObjectRank(10+i, rank);
SetObjectParent(10+i, 0);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "factory2.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("factory2.mod", false, rank);
SetPosition(10+i, Math::Vector(10.0f, 2.0f*i, -10.0f));
SetAngleZ(10+i, -Math::PI/2.0f);
SetAngleY(10+i, Math::PI);
@@ -2848,8 +2806,7 @@ bool CObject::CreateBuilding(Math::Vector pos, float angle, float height,
if ( m_type == OBJECT_REPAIR )
{
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "repair1.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("repair1.mod", false, rank);
SetPosition(0, pos);
SetAngleY(0, angle);
SetFloorHeight(0.0f);
@@ -2858,8 +2815,7 @@ bool CObject::CreateBuilding(Math::Vector pos, float angle, float height,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
SetObjectRank(1, rank);
SetObjectParent(1, 0);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "repair2.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("repair2.mod", false, rank);
SetPosition(1, Math::Vector(-11.0f, 13.5f, 0.0f));
SetAngleZ(1, Math::PI/2.0f);
@@ -2874,8 +2830,7 @@ bool CObject::CreateBuilding(Math::Vector pos, float angle, float height,
if ( m_type == OBJECT_DESTROYER )
{
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "destroy1.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("destroy1.mod", false, rank);
SetPosition(0, pos);
SetAngleY(0, angle);
SetFloorHeight(0.0f);
@@ -2884,8 +2839,7 @@ bool CObject::CreateBuilding(Math::Vector pos, float angle, float height,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
SetObjectRank(1, rank);
SetObjectParent(1, 0);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "destroy2.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("destroy2.mod", false, rank);
SetPosition(1, Math::Vector(0.0f, 0.0f, 0.0f));
m_terrain->AddBuildingLevel(pos, 7.0f, 9.0f, 1.0f, 0.5f);
@@ -2900,8 +2854,7 @@ bool CObject::CreateBuilding(Math::Vector pos, float angle, float height,
if ( m_type == OBJECT_STATION )
{
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "station.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("station.mod", false, rank);
SetPosition(0, pos);
SetAngleY(0, angle);
SetFloorHeight(0.0f);
@@ -2917,8 +2870,7 @@ bool CObject::CreateBuilding(Math::Vector pos, float angle, float height,
if ( m_type == OBJECT_CONVERT )
{
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "convert1.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("convert1.mod", false, rank);
SetPosition(0, pos);
SetAngleY(0, angle);
SetFloorHeight(0.0f);
@@ -2927,16 +2879,14 @@ bool CObject::CreateBuilding(Math::Vector pos, float angle, float height,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
SetObjectRank(1, rank);
SetObjectParent(1, 0);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "convert2.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("convert2.mod", false, rank);
SetPosition(1, Math::Vector(0.0f, 14.0f, 0.0f));
rank = m_engine->CreateObject();
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
SetObjectRank(2, rank);
SetObjectParent(2, 0);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "convert3.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("convert3.mod", false, rank);
SetPosition(2, Math::Vector(0.0f, 11.5f, 0.0f));
SetAngleX(2, -Math::PI*0.35f);
@@ -2944,8 +2894,7 @@ bool CObject::CreateBuilding(Math::Vector pos, float angle, float height,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
SetObjectRank(3, rank);
SetObjectParent(3, 0);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "convert3.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("convert3.mod", false, rank);
SetPosition(3, Math::Vector(0.0f, 11.5f, 0.0f));
SetAngleY(3, Math::PI);
SetAngleX(3, -Math::PI*0.35f);
@@ -2961,8 +2910,7 @@ bool CObject::CreateBuilding(Math::Vector pos, float angle, float height,
if ( m_type == OBJECT_TOWER )
{
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "tower.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("tower.mod", false, rank);
SetPosition(0, pos);
SetAngleY(0, angle);
SetFloorHeight(0.0f);
@@ -2971,8 +2919,7 @@ bool CObject::CreateBuilding(Math::Vector pos, float angle, float height,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
SetObjectRank(1, rank);
SetObjectParent(1, 0);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "roller2c.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("roller2c.mod", false, rank);
SetPosition(1, Math::Vector(0.0f, 20.0f, 0.0f));
SetAngleZ(1, Math::PI/2.0f);
@@ -2980,8 +2927,7 @@ bool CObject::CreateBuilding(Math::Vector pos, float angle, float height,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
SetObjectRank(2, rank);
SetObjectParent(2, 1);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "roller3c.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("roller3c.mod", false, rank);
SetPosition(2, Math::Vector(4.5f, 0.0f, 0.0f));
SetAngleZ(2, 0.0f);
@@ -2999,8 +2945,7 @@ bool CObject::CreateBuilding(Math::Vector pos, float angle, float height,
if ( m_type == OBJECT_NUCLEAR )
{
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "nuclear1.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("nuclear1.mod", false, rank);
SetPosition(0, pos);
SetAngleY(0, angle);
SetFloorHeight(0.0f);
@@ -3009,8 +2954,7 @@ bool CObject::CreateBuilding(Math::Vector pos, float angle, float height,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
SetObjectRank(1, rank);
SetObjectParent(1, 0);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "nuclear2.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("nuclear2.mod", false, rank);
SetPosition(1, Math::Vector(20.0f, 10.0f, 0.0f));
SetAngleZ(1, 135.0f*Math::PI/180.0f);
@@ -3026,8 +2970,7 @@ bool CObject::CreateBuilding(Math::Vector pos, float angle, float height,
if ( m_type == OBJECT_PARA )
{
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "para.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("para.mod", false, rank);
SetPosition(0, pos);
SetAngleY(0, angle);
SetFloorHeight(0.0f);
@@ -3052,8 +2995,7 @@ bool CObject::CreateBuilding(Math::Vector pos, float angle, float height,
if ( m_type == OBJECT_SAFE )
{
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "safe1.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("safe1.mod", false, rank);
SetPosition(0, pos);
SetAngleY(0, angle);
SetFloorHeight(0.0f);
@@ -3062,16 +3004,14 @@ bool CObject::CreateBuilding(Math::Vector pos, float angle, float height,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
SetObjectRank(1, rank);
SetObjectParent(1, 0);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "safe2.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("safe2.mod", false, rank);
SetZoom(1, 1.05f);
rank = m_engine->CreateObject();
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
SetObjectRank(2, rank);
SetObjectParent(2, 0);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "safe3.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("safe3.mod", false, rank);
SetZoom(2, 1.05f);
m_terrain->AddBuildingLevel(pos, 18.0f, 20.0f, 1.0f, 0.5f);
@@ -3084,8 +3024,7 @@ bool CObject::CreateBuilding(Math::Vector pos, float angle, float height,
if ( m_type == OBJECT_HUSTON )
{
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "huston1.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("huston1.mod", false, rank);
SetPosition(0, pos);
SetAngleY(0, angle);
SetFloorHeight(0.0f);
@@ -3094,8 +3033,7 @@ bool CObject::CreateBuilding(Math::Vector pos, float angle, float height,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
SetObjectRank(1, rank);
SetObjectParent(1, 0);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "huston2.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("huston2.mod", false, rank);
SetPosition(1, Math::Vector(0.0f, 39.0f, 30.0f));
SetAngleY(1, -Math::PI/2.0f);
SetZoom(1, 3.0f);
@@ -3104,8 +3042,7 @@ bool CObject::CreateBuilding(Math::Vector pos, float angle, float height,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
SetObjectRank(2, rank);
SetObjectParent(2, 1);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "huston3.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("huston3.mod", false, rank);
SetPosition(2, Math::Vector(0.0f, 4.5f, 1.9f));
CreateCrashSphere(Math::Vector( 15.0f, 6.0f, -53.0f), 16.0f, SOUND_BOUMm, 0.45f);
@@ -3128,8 +3065,7 @@ bool CObject::CreateBuilding(Math::Vector pos, float angle, float height,
if ( m_type == OBJECT_TARGET1 )
{
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "target1.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("target1.mod", false, rank);
SetPosition(0, pos);
SetAngleY(0, angle);
SetZoom(0, 1.5f);
@@ -3158,8 +3094,7 @@ bool CObject::CreateBuilding(Math::Vector pos, float angle, float height,
if ( m_type == OBJECT_TARGET2 )
{
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "target2.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("target2.mod", false, rank);
SetPosition(0, pos);
SetAngleY(0, angle);
SetFloorHeight(0.0f);
@@ -3169,8 +3104,7 @@ bool CObject::CreateBuilding(Math::Vector pos, float angle, float height,
if ( m_type == OBJECT_NEST )
{
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "nest.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("nest.mod", false, rank);
SetPosition(0, pos);
SetAngleY(0, angle);
SetFloorHeight(0.0f);
@@ -3182,8 +3116,7 @@ bool CObject::CreateBuilding(Math::Vector pos, float angle, float height,
if ( m_type == OBJECT_START )
{
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "start.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("start.mod", false, rank);
SetPosition(0, pos);
SetAngleY(0, angle);
SetFloorHeight(0.0f);
@@ -3193,8 +3126,7 @@ bool CObject::CreateBuilding(Math::Vector pos, float angle, float height,
if ( m_type == OBJECT_END )
{
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "end.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("end.mod", false, rank);
SetPosition(0, pos);
SetAngleY(0, angle);
SetFloorHeight(0.0f);
@@ -3214,9 +3146,8 @@ bool CObject::CreateBuilding(Math::Vector pos, float angle, float height,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX);
pPower->SetObjectRank(0, rank);
- if ( power <= 1.0f ) pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "power.mod"));
- else pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "atomic.mod"));
- pModFile->CreateEngineObject(rank);
+ if ( power <= 1.0f ) modelManager->AddModelReference("power.mod", false, rank);
+ else modelManager->AddModelReference("atomic.mod", false, rank);
pPower->SetPosition(0, GetCharacter()->posPower);
pPower->CreateCrashSphere(Math::Vector(0.0f, 1.0f, 0.0f), 1.0f, SOUND_BOUMm, 0.45f);
@@ -3237,7 +3168,6 @@ bool CObject::CreateBuilding(Math::Vector pos, float angle, float height,
CreateOtherObject(type);
m_engine->LoadAllTextures();
- delete pModFile;
return true;
}
@@ -3246,11 +3176,10 @@ bool CObject::CreateBuilding(Math::Vector pos, float angle, float height,
bool CObject::CreateResource(Math::Vector pos, float angle, ObjectType type,
float power)
{
- Gfx::CModelFile* pModFile;
int rank;
float radius, height;
- pModFile = new Gfx::CModelFile(m_iMan);
+ Gfx::CModelManager* modelManager = Gfx::CModelManager::GetInstancePointer();
SetType(type);
@@ -3260,46 +3189,44 @@ bool CObject::CreateResource(Math::Vector pos, float angle, ObjectType type,
SetEnergy(power);
std::string name;
- if ( type == OBJECT_STONE ) name = m_app->GetDataFilePath(DIR_MODEL, "stone.mod");
- if ( type == OBJECT_URANIUM ) name = m_app->GetDataFilePath(DIR_MODEL, "uranium.mod");
- if ( type == OBJECT_METAL ) name = m_app->GetDataFilePath(DIR_MODEL, "metal.mod");
- if ( type == OBJECT_POWER ) name = m_app->GetDataFilePath(DIR_MODEL, "power.mod");
- if ( type == OBJECT_ATOMIC ) name = m_app->GetDataFilePath(DIR_MODEL, "atomic.mod");
- if ( type == OBJECT_BULLET ) name = m_app->GetDataFilePath(DIR_MODEL, "bullet.mod");
- if ( type == OBJECT_BBOX ) name = m_app->GetDataFilePath(DIR_MODEL, "bbox.mod");
- if ( type == OBJECT_KEYa ) name = m_app->GetDataFilePath(DIR_MODEL, "keya.mod");
- if ( type == OBJECT_KEYb ) name = m_app->GetDataFilePath(DIR_MODEL, "keyb.mod");
- if ( type == OBJECT_KEYc ) name = m_app->GetDataFilePath(DIR_MODEL, "keyc.mod");
- if ( type == OBJECT_KEYd ) name = m_app->GetDataFilePath(DIR_MODEL, "keyd.mod");
- if ( type == OBJECT_TNT ) name = m_app->GetDataFilePath(DIR_MODEL, "tnt.mod");
- if ( type == OBJECT_SCRAP1 ) name = m_app->GetDataFilePath(DIR_MODEL, "scrap1.mod");
- if ( type == OBJECT_SCRAP2 ) name = m_app->GetDataFilePath(DIR_MODEL, "scrap2.mod");
- if ( type == OBJECT_SCRAP3 ) name = m_app->GetDataFilePath(DIR_MODEL, "scrap3.mod");
- if ( type == OBJECT_SCRAP4 ) name = m_app->GetDataFilePath(DIR_MODEL, "scrap4.mod");
- if ( type == OBJECT_SCRAP5 ) name = m_app->GetDataFilePath(DIR_MODEL, "scrap5.mod");
- if ( type == OBJECT_BOMB ) name = m_app->GetDataFilePath(DIR_MODEL, "bomb.mod");
- if ( type == OBJECT_WAYPOINT ) name = m_app->GetDataFilePath(DIR_MODEL, "waypoint.mod");
- if ( type == OBJECT_SHOW ) name = m_app->GetDataFilePath(DIR_MODEL, "show.mod");
- if ( type == OBJECT_WINFIRE ) name = m_app->GetDataFilePath(DIR_MODEL, "winfire.mod");
- if ( type == OBJECT_BAG ) name = m_app->GetDataFilePath(DIR_MODEL, "bag.mod");
- if ( type == OBJECT_MARKSTONE ) name = m_app->GetDataFilePath(DIR_MODEL, "cross1.mod");
- if ( type == OBJECT_MARKURANIUM ) name = m_app->GetDataFilePath(DIR_MODEL, "cross3.mod");
- if ( type == OBJECT_MARKPOWER ) name = m_app->GetDataFilePath(DIR_MODEL, "cross2.mod");
- if ( type == OBJECT_MARKKEYa ) name = m_app->GetDataFilePath(DIR_MODEL, "crossa.mod");
- if ( type == OBJECT_MARKKEYb ) name = m_app->GetDataFilePath(DIR_MODEL, "crossb.mod");
- if ( type == OBJECT_MARKKEYc ) name = m_app->GetDataFilePath(DIR_MODEL, "crossc.mod");
- if ( type == OBJECT_MARKKEYd ) name = m_app->GetDataFilePath(DIR_MODEL, "crossd.mod");
- if ( type == OBJECT_EGG ) name = m_app->GetDataFilePath(DIR_MODEL, "egg.mod");
-
- pModFile->ReadModel(name);
- pModFile->CreateEngineObject(rank);
+ if ( type == OBJECT_STONE ) name = "stone.mod";
+ if ( type == OBJECT_URANIUM ) name = "uranium.mod";
+ if ( type == OBJECT_METAL ) name = "metal.mod";
+ if ( type == OBJECT_POWER ) name = "power.mod";
+ if ( type == OBJECT_ATOMIC ) name = "atomic.mod";
+ if ( type == OBJECT_BULLET ) name = "bullet.mod";
+ if ( type == OBJECT_BBOX ) name = "bbox.mod";
+ if ( type == OBJECT_KEYa ) name = "keya.mod";
+ if ( type == OBJECT_KEYb ) name = "keyb.mod";
+ if ( type == OBJECT_KEYc ) name = "keyc.mod";
+ if ( type == OBJECT_KEYd ) name = "keyd.mod";
+ if ( type == OBJECT_TNT ) name = "tnt.mod";
+ if ( type == OBJECT_SCRAP1 ) name = "scrap1.mod";
+ if ( type == OBJECT_SCRAP2 ) name = "scrap2.mod";
+ if ( type == OBJECT_SCRAP3 ) name = "scrap3.mod";
+ if ( type == OBJECT_SCRAP4 ) name = "scrap4.mod";
+ if ( type == OBJECT_SCRAP5 ) name = "scrap5.mod";
+ if ( type == OBJECT_BOMB ) name = "bomb.mod";
+ if ( type == OBJECT_WAYPOINT ) name = "waypoint.mod";
+ if ( type == OBJECT_SHOW ) name = "show.mod";
+ if ( type == OBJECT_WINFIRE ) name = "winfire.mod";
+ if ( type == OBJECT_BAG ) name = "bag.mod";
+ if ( type == OBJECT_MARKSTONE ) name = "cross1.mod";
+ if ( type == OBJECT_MARKURANIUM ) name = "cross3.mod";
+ if ( type == OBJECT_MARKPOWER ) name = "cross2.mod";
+ if ( type == OBJECT_MARKKEYa ) name = "crossa.mod";
+ if ( type == OBJECT_MARKKEYb ) name = "crossb.mod";
+ if ( type == OBJECT_MARKKEYc ) name = "crossc.mod";
+ if ( type == OBJECT_MARKKEYd ) name = "crossd.mod";
+ if ( type == OBJECT_EGG ) name = "egg.mod";
+
+ modelManager->AddModelReference(name, false, rank);
SetPosition(0, pos);
SetAngleY(0, angle);
if ( type == OBJECT_SHOW ) // remains in the air?
{
- delete pModFile;
return true;
}
@@ -3352,7 +3279,6 @@ bool CObject::CreateResource(Math::Vector pos, float angle, ObjectType type,
pos.y += height;
SetPosition(0, pos); // to display the shadows immediately
- delete pModFile;
return true;
}
@@ -3360,36 +3286,34 @@ bool CObject::CreateResource(Math::Vector pos, float angle, ObjectType type,
bool CObject::CreateFlag(Math::Vector pos, float angle, ObjectType type)
{
- Gfx::CModelFile* pModFile;
int rank, i;
- pModFile = new Gfx::CModelFile(m_iMan);
+ Gfx::CModelManager* modelManager = Gfx::CModelManager::GetInstancePointer();
SetType(type);
std::string name;
name = "";
- if ( type == OBJECT_FLAGb ) name = m_app->GetDataFilePath(DIR_MODEL, "flag1b.mod");
- if ( type == OBJECT_FLAGr ) name = m_app->GetDataFilePath(DIR_MODEL, "flag1r.mod");
- if ( type == OBJECT_FLAGg ) name = m_app->GetDataFilePath(DIR_MODEL, "flag1g.mod");
- if ( type == OBJECT_FLAGy ) name = m_app->GetDataFilePath(DIR_MODEL, "flag1y.mod");
- if ( type == OBJECT_FLAGv ) name = m_app->GetDataFilePath(DIR_MODEL, "flag1v.mod");
+ if ( type == OBJECT_FLAGb ) name = "flag1b.mod";
+ if ( type == OBJECT_FLAGr ) name = "flag1r.mod";
+ if ( type == OBJECT_FLAGg ) name = "flag1g.mod";
+ if ( type == OBJECT_FLAGy ) name = "flag1y.mod";
+ if ( type == OBJECT_FLAGv ) name = "flag1v.mod";
rank = m_engine->CreateObject();
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX); // it is a stationary object
SetObjectRank(0, rank);
- pModFile->ReadModel(name);
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference(name, false, rank);
SetPosition(0, pos);
SetAngleY(0, angle);
name = "";
- if ( type == OBJECT_FLAGb ) name = m_app->GetDataFilePath(DIR_MODEL, "flag2b.mod");
- if ( type == OBJECT_FLAGr ) name = m_app->GetDataFilePath(DIR_MODEL, "flag2r.mod");
- if ( type == OBJECT_FLAGg ) name = m_app->GetDataFilePath(DIR_MODEL, "flag2g.mod");
- if ( type == OBJECT_FLAGy ) name = m_app->GetDataFilePath(DIR_MODEL, "flag2y.mod");
- if ( type == OBJECT_FLAGv ) name = m_app->GetDataFilePath(DIR_MODEL, "flag2v.mod");
+ if ( type == OBJECT_FLAGb ) name = "flag2b.mod";
+ if ( type == OBJECT_FLAGr ) name = "flag2r.mod";
+ if ( type == OBJECT_FLAGg ) name = "flag2g.mod";
+ if ( type == OBJECT_FLAGy ) name = "flag2y.mod";
+ if ( type == OBJECT_FLAGv ) name = "flag2v.mod";
for ( i=0 ; i<4 ; i++ )
{
@@ -3397,8 +3321,7 @@ bool CObject::CreateFlag(Math::Vector pos, float angle, ObjectType type)
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
SetObjectRank(1+i, rank);
SetObjectParent(1+i, i);
- pModFile->ReadModel(name);
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference(name, false, rank);
if ( i == 0 ) SetPosition(1+i, Math::Vector(0.15f, 5.0f, 0.0f));
else SetPosition(1+i, Math::Vector(0.79f, 0.0f, 0.0f));
}
@@ -3414,7 +3337,6 @@ bool CObject::CreateFlag(Math::Vector pos, float angle, ObjectType type)
pos = GetPosition(0);
SetPosition(0, pos); // to display the shadows immediately
- delete pModFile;
return true;
}
@@ -3423,10 +3345,9 @@ bool CObject::CreateFlag(Math::Vector pos, float angle, ObjectType type)
bool CObject::CreateBarrier(Math::Vector pos, float angle, float height,
ObjectType type)
{
- Gfx::CModelFile* pModFile;
int rank;
- pModFile = new Gfx::CModelFile(m_iMan);
+ Gfx::CModelManager* modelManager = Gfx::CModelManager::GetInstancePointer();
SetType(type);
@@ -3435,8 +3356,7 @@ bool CObject::CreateBarrier(Math::Vector pos, float angle, float height,
rank = m_engine->CreateObject();
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX);
SetObjectRank(0, rank);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "barrier0.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("barrier0.mod", false, rank);
SetPosition(0, pos);
SetAngleY(0, angle);
@@ -3452,8 +3372,7 @@ bool CObject::CreateBarrier(Math::Vector pos, float angle, float height,
rank = m_engine->CreateObject();
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX);
SetObjectRank(0, rank);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "barrier1.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("barrier1.mod", false, rank);
SetPosition(0, pos);
SetAngleY(0, angle);
@@ -3471,8 +3390,7 @@ bool CObject::CreateBarrier(Math::Vector pos, float angle, float height,
rank = m_engine->CreateObject();
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX);
SetObjectRank(0, rank);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "barrier2.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("barrier2.mod", false, rank);
SetPosition(0, pos);
SetAngleY(0, angle);
@@ -3490,8 +3408,7 @@ bool CObject::CreateBarrier(Math::Vector pos, float angle, float height,
rank = m_engine->CreateObject();
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX);
SetObjectRank(0, rank);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "barrier3.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("barrier3.mod", false, rank);
SetPosition(0, pos);
SetAngleY(0, angle);
@@ -3515,7 +3432,6 @@ bool CObject::CreateBarrier(Math::Vector pos, float angle, float height,
pos.y += height;
SetPosition(0, pos);
- delete pModFile;
return true;
}
@@ -3524,10 +3440,9 @@ bool CObject::CreateBarrier(Math::Vector pos, float angle, float height,
bool CObject::CreatePlant(Math::Vector pos, float angle, float height,
ObjectType type)
{
- Gfx::CModelFile* pModFile;
int rank;
- pModFile = new Gfx::CModelFile(m_iMan);
+ Gfx::CModelManager* modelManager = Gfx::CModelManager::GetInstancePointer();
SetType(type);
@@ -3540,12 +3455,11 @@ bool CObject::CreatePlant(Math::Vector pos, float angle, float height,
rank = m_engine->CreateObject();
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX);
SetObjectRank(0, rank);
- if ( type == OBJECT_PLANT0 ) pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "plant0.mod"));
- if ( type == OBJECT_PLANT1 ) pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "plant1.mod"));
- if ( type == OBJECT_PLANT2 ) pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "plant2.mod"));
- if ( type == OBJECT_PLANT3 ) pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "plant3.mod"));
- if ( type == OBJECT_PLANT4 ) pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "plant4.mod"));
- pModFile->CreateEngineObject(rank);
+ if ( type == OBJECT_PLANT0 ) modelManager->AddModelReference("plant0.mod", false, rank);
+ if ( type == OBJECT_PLANT1 ) modelManager->AddModelReference("plant1.mod", false, rank);
+ if ( type == OBJECT_PLANT2 ) modelManager->AddModelReference("plant2.mod", false, rank);
+ if ( type == OBJECT_PLANT3 ) modelManager->AddModelReference("plant3.mod", false, rank);
+ if ( type == OBJECT_PLANT4 ) modelManager->AddModelReference("plant4.mod", false, rank);
SetPosition(0, pos);
SetAngleY(0, angle);
@@ -3565,10 +3479,9 @@ bool CObject::CreatePlant(Math::Vector pos, float angle, float height,
rank = m_engine->CreateObject();
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX);
SetObjectRank(0, rank);
- if ( type == OBJECT_PLANT5 ) pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "plant5.mod"));
- if ( type == OBJECT_PLANT6 ) pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "plant6.mod"));
- if ( type == OBJECT_PLANT7 ) pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "plant7.mod"));
- pModFile->CreateEngineObject(rank);
+ if ( type == OBJECT_PLANT5 ) modelManager->AddModelReference("plant5.mod", false, rank);
+ if ( type == OBJECT_PLANT6 ) modelManager->AddModelReference("plant6.mod", false, rank);
+ if ( type == OBJECT_PLANT7 ) modelManager->AddModelReference("plant7.mod", false, rank);
SetPosition(0, pos);
SetAngleY(0, angle);
@@ -3584,9 +3497,8 @@ bool CObject::CreatePlant(Math::Vector pos, float angle, float height,
rank = m_engine->CreateObject();
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX);
SetObjectRank(0, rank);
- if ( type == OBJECT_PLANT8 ) pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "plant8.mod"));
- if ( type == OBJECT_PLANT9 ) pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "plant9.mod"));
- pModFile->CreateEngineObject(rank);
+ if ( type == OBJECT_PLANT8 ) modelManager->AddModelReference("plant8.mod", false, rank);
+ if ( type == OBJECT_PLANT9 ) modelManager->AddModelReference("plant9.mod", false, rank);
SetPosition(0, pos);
SetAngleY(0, angle);
@@ -3605,12 +3517,11 @@ bool CObject::CreatePlant(Math::Vector pos, float angle, float height,
rank = m_engine->CreateObject();
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX);
SetObjectRank(0, rank);
- if ( type == OBJECT_PLANT10 ) pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "plant10.mod"));
- if ( type == OBJECT_PLANT11 ) pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "plant11.mod"));
- if ( type == OBJECT_PLANT12 ) pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "plant12.mod"));
- if ( type == OBJECT_PLANT13 ) pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "plant13.mod"));
- if ( type == OBJECT_PLANT14 ) pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "plant14.mod"));
- pModFile->CreateEngineObject(rank);
+ if ( type == OBJECT_PLANT10 ) modelManager->AddModelReference("plant10.mod", false, rank);
+ if ( type == OBJECT_PLANT11 ) modelManager->AddModelReference("plant11.mod", false, rank);
+ if ( type == OBJECT_PLANT12 ) modelManager->AddModelReference("plant12.mod", false, rank);
+ if ( type == OBJECT_PLANT13 ) modelManager->AddModelReference("plant13.mod", false, rank);
+ if ( type == OBJECT_PLANT14 ) modelManager->AddModelReference("plant14.mod", false, rank);
SetPosition(0, pos);
SetAngleY(0, angle);
@@ -3630,12 +3541,11 @@ bool CObject::CreatePlant(Math::Vector pos, float angle, float height,
rank = m_engine->CreateObject();
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX);
SetObjectRank(0, rank);
- if ( type == OBJECT_PLANT15 ) pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "plant15.mod"));
- if ( type == OBJECT_PLANT16 ) pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "plant16.mod"));
- if ( type == OBJECT_PLANT17 ) pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "plant17.mod"));
- if ( type == OBJECT_PLANT18 ) pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "plant18.mod"));
- if ( type == OBJECT_PLANT19 ) pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "plant19.mod"));
- pModFile->CreateEngineObject(rank);
+ if ( type == OBJECT_PLANT15 ) modelManager->AddModelReference("plant15.mod", false, rank);
+ if ( type == OBJECT_PLANT16 ) modelManager->AddModelReference("plant16.mod", false, rank);
+ if ( type == OBJECT_PLANT17 ) modelManager->AddModelReference("plant17.mod", false, rank);
+ if ( type == OBJECT_PLANT18 ) modelManager->AddModelReference("plant18.mod", false, rank);
+ if ( type == OBJECT_PLANT19 ) modelManager->AddModelReference("plant19.mod", false, rank);
SetPosition(0, pos);
SetAngleY(0, angle);
@@ -3654,8 +3564,7 @@ bool CObject::CreatePlant(Math::Vector pos, float angle, float height,
rank = m_engine->CreateObject();
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX);
SetObjectRank(0, rank);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "tree0.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("tree0.mod", false, rank);
SetPosition(0, pos);
SetAngleY(0, angle);
@@ -3672,8 +3581,7 @@ bool CObject::CreatePlant(Math::Vector pos, float angle, float height,
rank = m_engine->CreateObject();
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX);
SetObjectRank(0, rank);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "tree1.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("tree1.mod", false, rank);
SetPosition(0, pos);
SetAngleY(0, angle);
@@ -3691,8 +3599,7 @@ bool CObject::CreatePlant(Math::Vector pos, float angle, float height,
rank = m_engine->CreateObject();
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX);
SetObjectRank(0, rank);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "tree2.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("tree2.mod", false, rank);
SetPosition(0, pos);
SetAngleY(0, angle);
@@ -3710,8 +3617,7 @@ bool CObject::CreatePlant(Math::Vector pos, float angle, float height,
rank = m_engine->CreateObject();
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX);
SetObjectRank(0, rank);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "tree3.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("tree3.mod", false, rank);
SetPosition(0, pos);
SetAngleY(0, angle);
@@ -3728,8 +3634,7 @@ bool CObject::CreatePlant(Math::Vector pos, float angle, float height,
rank = m_engine->CreateObject();
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX);
SetObjectRank(0, rank);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "tree4.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("tree4.mod", false, rank);
SetPosition(0, pos);
SetAngleY(0, angle);
@@ -3745,8 +3650,7 @@ bool CObject::CreatePlant(Math::Vector pos, float angle, float height,
rank = m_engine->CreateObject();
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX);
SetObjectRank(0, rank);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "tree5.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("tree5.mod", false, rank);
SetPosition(0, pos);
SetAngleY(0, angle);
@@ -3767,7 +3671,6 @@ bool CObject::CreatePlant(Math::Vector pos, float angle, float height,
pos.y += height;
SetPosition(0, pos);
- delete pModFile;
return true;
}
@@ -3776,10 +3679,9 @@ bool CObject::CreatePlant(Math::Vector pos, float angle, float height,
bool CObject::CreateMushroom(Math::Vector pos, float angle, float height,
ObjectType type)
{
- Gfx::CModelFile* pModFile;
int rank;
- pModFile = new Gfx::CModelFile(m_iMan);
+ Gfx::CModelManager* modelManager = Gfx::CModelManager::GetInstancePointer();
SetType(type);
@@ -3788,8 +3690,7 @@ bool CObject::CreateMushroom(Math::Vector pos, float angle, float height,
rank = m_engine->CreateObject();
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX);
SetObjectRank(0, rank);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "mush1.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("mush1.mod", false, rank);
SetPosition(0, pos);
SetAngleY(0, angle);
@@ -3805,8 +3706,7 @@ bool CObject::CreateMushroom(Math::Vector pos, float angle, float height,
rank = m_engine->CreateObject();
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX);
SetObjectRank(0, rank);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "mush2.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("mush2.mod", false, rank);
SetPosition(0, pos);
SetAngleY(0, angle);
@@ -3827,7 +3727,6 @@ bool CObject::CreateMushroom(Math::Vector pos, float angle, float height,
pos.y += height;
SetPosition(0, pos);
- delete pModFile;
return true;
}
@@ -3836,14 +3735,13 @@ bool CObject::CreateMushroom(Math::Vector pos, float angle, float height,
bool CObject::CreateTeen(Math::Vector pos, float angle, float zoom, float height,
ObjectType type)
{
- Gfx::CModelFile* pModFile;
Math::Matrix* mat;
Gfx::Color color;
int rank;
float fShadow;
bool bFloorAdjust = true;
- pModFile = new Gfx::CModelFile(m_iMan);
+ Gfx::CModelManager* modelManager = Gfx::CModelManager::GetInstancePointer();
SetType(type);
@@ -3854,8 +3752,7 @@ bool CObject::CreateTeen(Math::Vector pos, float angle, float zoom, float height
rank = m_engine->CreateObject();
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX);
SetObjectRank(0, rank);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "teen0.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("teen0.mod", false, rank);
SetPosition(0, pos);
SetAngleY(0, angle);
SetZoom(0, zoom);
@@ -3874,8 +3771,7 @@ bool CObject::CreateTeen(Math::Vector pos, float angle, float zoom, float height
rank = m_engine->CreateObject();
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX);
SetObjectRank(0, rank);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "teen1.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("teen1.mod", false, rank);
SetPosition(0, pos);
SetAngleY(0, angle);
SetZoom(0, zoom);
@@ -3896,8 +3792,7 @@ bool CObject::CreateTeen(Math::Vector pos, float angle, float zoom, float height
rank = m_engine->CreateObject();
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX);
SetObjectRank(0, rank);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "teen2.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("teen2.mod", false, rank);
SetPosition(0, pos);
SetAngleY(0, angle);
SetZoom(0, zoom);
@@ -3919,8 +3814,7 @@ bool CObject::CreateTeen(Math::Vector pos, float angle, float zoom, float height
//? m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX);
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_METAL);
SetObjectRank(0, rank);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "teen3.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("teen3.mod", false, rank);
SetPosition(0, pos);
SetAngleY(0, angle);
SetZoom(0, zoom);
@@ -3935,8 +3829,7 @@ bool CObject::CreateTeen(Math::Vector pos, float angle, float zoom, float height
rank = m_engine->CreateObject();
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX);
SetObjectRank(0, rank);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "teen4.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("teen4.mod", false, rank);
SetPosition(0, pos);
SetAngleY(0, angle);
SetZoom(0, zoom);
@@ -3957,8 +3850,7 @@ bool CObject::CreateTeen(Math::Vector pos, float angle, float zoom, float height
rank = m_engine->CreateObject();
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX);
SetObjectRank(0, rank);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "teen5.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("teen5.mod", false, rank);
SetPosition(0, pos);
SetAngleY(0, angle);
SetZoom(0, zoom);
@@ -3974,8 +3866,7 @@ bool CObject::CreateTeen(Math::Vector pos, float angle, float zoom, float height
rank = m_engine->CreateObject();
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX);
SetObjectRank(0, rank);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "teen6.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("teen6.mod", false, rank);
SetPosition(0, pos);
SetAngleY(0, angle);
SetZoom(0, zoom);
@@ -3995,8 +3886,7 @@ bool CObject::CreateTeen(Math::Vector pos, float angle, float zoom, float height
rank = m_engine->CreateObject();
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX);
SetObjectRank(0, rank);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "teen7.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("teen7.mod", false, rank);
SetPosition(0, pos);
SetAngleY(0, angle);
SetZoom(0, zoom);
@@ -4016,8 +3906,7 @@ bool CObject::CreateTeen(Math::Vector pos, float angle, float zoom, float height
rank = m_engine->CreateObject();
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX);
SetObjectRank(0, rank);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "teen8.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("teen8.mod", false, rank);
SetPosition(0, pos);
SetAngleY(0, angle);
SetZoom(0, zoom);
@@ -4038,8 +3927,7 @@ bool CObject::CreateTeen(Math::Vector pos, float angle, float zoom, float height
rank = m_engine->CreateObject();
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX);
SetObjectRank(0, rank);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "teen9.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("teen9.mod", false, rank);
SetPosition(0, pos);
SetAngleY(0, angle);
SetZoom(0, zoom);
@@ -4060,8 +3948,7 @@ bool CObject::CreateTeen(Math::Vector pos, float angle, float zoom, float height
rank = m_engine->CreateObject();
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX);
SetObjectRank(0, rank);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "teen10.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("teen10.mod", false, rank);
SetPosition(0, pos);
SetAngleY(0, angle);
SetZoom(0, zoom);
@@ -4086,8 +3973,7 @@ bool CObject::CreateTeen(Math::Vector pos, float angle, float zoom, float height
rank = m_engine->CreateObject();
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX);
SetObjectRank(0, rank);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "teen11.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("teen11.mod", false, rank);
SetPosition(0, pos);
SetAngleY(0, angle);
SetFloorHeight(0.0f);
@@ -4111,8 +3997,7 @@ bool CObject::CreateTeen(Math::Vector pos, float angle, float zoom, float height
//? m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX);
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_METAL);
SetObjectRank(0, rank);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "teen12.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("teen12.mod", false, rank);
SetPosition(0, pos);
SetAngleY(0, angle);
SetZoom(0, zoom);
@@ -4127,8 +4012,7 @@ bool CObject::CreateTeen(Math::Vector pos, float angle, float zoom, float height
rank = m_engine->CreateObject();
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX);
SetObjectRank(0, rank);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "teen13.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("teen13.mod", false, rank);
SetPosition(0, pos);
SetAngleY(0, angle);
SetZoom(0, zoom);
@@ -4152,8 +4036,7 @@ bool CObject::CreateTeen(Math::Vector pos, float angle, float zoom, float height
rank = m_engine->CreateObject();
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX);
SetObjectRank(0, rank);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "teen14.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("teen14.mod", false, rank);
SetPosition(0, pos);
SetAngleY(0, angle);
SetZoom(0, zoom);
@@ -4177,8 +4060,7 @@ bool CObject::CreateTeen(Math::Vector pos, float angle, float zoom, float height
rank = m_engine->CreateObject();
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX);
SetObjectRank(0, rank);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "teen15.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("teen15.mod", false, rank);
SetPosition(0, pos);
SetAngleY(0, angle);
SetZoom(0, zoom);
@@ -4202,8 +4084,7 @@ bool CObject::CreateTeen(Math::Vector pos, float angle, float zoom, float height
rank = m_engine->CreateObject();
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX);
SetObjectRank(0, rank);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "teen16.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("teen16.mod", false, rank);
SetPosition(0, pos);
SetAngleY(0, angle);
SetZoom(0, zoom);
@@ -4220,8 +4101,7 @@ bool CObject::CreateTeen(Math::Vector pos, float angle, float zoom, float height
rank = m_engine->CreateObject();
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX);
SetObjectRank(0, rank);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "teen17.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("teen17.mod", false, rank);
SetPosition(0, pos);
SetAngleY(0, angle);
SetZoom(0, zoom);
@@ -4236,8 +4116,7 @@ bool CObject::CreateTeen(Math::Vector pos, float angle, float zoom, float height
rank = m_engine->CreateObject();
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX);
SetObjectRank(0, rank);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "teen18.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("teen18.mod", false, rank);
SetPosition(0, pos);
SetAngleY(0, angle);
SetZoom(0, zoom);
@@ -4252,8 +4131,7 @@ bool CObject::CreateTeen(Math::Vector pos, float angle, float zoom, float height
rank = m_engine->CreateObject();
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX);
SetObjectRank(0, rank);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "teen19.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("teen19.mod", false, rank);
SetPosition(0, pos);
SetAngleY(0, angle);
SetZoom(0, zoom);
@@ -4268,8 +4146,7 @@ bool CObject::CreateTeen(Math::Vector pos, float angle, float zoom, float height
rank = m_engine->CreateObject();
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX);
SetObjectRank(0, rank);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "teen20.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("teen20.mod", false, rank);
SetPosition(0, pos);
SetAngleY(0, angle);
SetZoom(0, zoom);
@@ -4289,8 +4166,7 @@ bool CObject::CreateTeen(Math::Vector pos, float angle, float zoom, float height
rank = m_engine->CreateObject();
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX);
SetObjectRank(0, rank);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "teen21.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("teen21.mod", false, rank);
SetPosition(0, pos);
SetAngleY(0, angle);
SetZoom(0, zoom);
@@ -4301,8 +4177,7 @@ bool CObject::CreateTeen(Math::Vector pos, float angle, float zoom, float height
rank = m_engine->CreateObject();
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX);
SetObjectRank(0, rank);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "teen22.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("teen22.mod", false, rank);
SetPosition(0, pos);
SetAngleY(0, angle);
SetZoom(0, zoom);
@@ -4318,8 +4193,7 @@ bool CObject::CreateTeen(Math::Vector pos, float angle, float zoom, float height
rank = m_engine->CreateObject();
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX);
SetObjectRank(0, rank);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "teen23.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("teen23.mod", false, rank);
SetPosition(0, pos);
SetAngleY(0, angle);
SetZoom(0, zoom);
@@ -4345,8 +4219,7 @@ bool CObject::CreateTeen(Math::Vector pos, float angle, float zoom, float height
rank = m_engine->CreateObject();
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX);
SetObjectRank(0, rank);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "teen24.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("teen24.mod", false, rank);
SetPosition(0, pos);
SetAngleY(0, angle);
SetZoom(0, zoom);
@@ -4361,8 +4234,7 @@ bool CObject::CreateTeen(Math::Vector pos, float angle, float zoom, float height
rank = m_engine->CreateObject();
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX);
SetObjectRank(0, rank);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "teen25.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("teen25.mod", false, rank);
SetPosition(0, pos);
SetAngleY(0, angle);
SetZoom(0, zoom);
@@ -4377,8 +4249,7 @@ bool CObject::CreateTeen(Math::Vector pos, float angle, float zoom, float height
rank = m_engine->CreateObject();
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX);
SetObjectRank(0, rank);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "teen26.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("teen26.mod", false, rank);
SetPosition(0, pos);
SetAngleY(0, angle);
SetZoom(0, zoom);
@@ -4401,8 +4272,7 @@ bool CObject::CreateTeen(Math::Vector pos, float angle, float zoom, float height
rank = m_engine->CreateObject();
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX);
SetObjectRank(0, rank);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "teen27.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("teen27.mod", false, rank);
SetPosition(0, pos);
SetAngleY(0, angle);
SetZoom(0, zoom);
@@ -4417,8 +4287,7 @@ bool CObject::CreateTeen(Math::Vector pos, float angle, float zoom, float height
//? m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX);
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_METAL);
SetObjectRank(0, rank);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "teen28.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("teen28.mod", false, rank);
SetPosition(0, pos);
SetAngleY(0, angle);
SetZoom(0, zoom);
@@ -4432,8 +4301,7 @@ bool CObject::CreateTeen(Math::Vector pos, float angle, float zoom, float height
rank = m_engine->CreateObject();
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX);
SetObjectRank(0, rank);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "teen29.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("teen29.mod", false, rank);
SetPosition(0, pos);
SetAngleY(0, angle);
SetZoom(0, zoom);
@@ -4445,8 +4313,7 @@ bool CObject::CreateTeen(Math::Vector pos, float angle, float zoom, float height
rank = m_engine->CreateObject();
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX);
SetObjectRank(0, rank);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "teen30.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("teen30.mod", false, rank);
SetPosition(0, pos);
SetAngleY(0, angle);
SetZoom(0, zoom);
@@ -4461,8 +4328,7 @@ bool CObject::CreateTeen(Math::Vector pos, float angle, float zoom, float height
rank = m_engine->CreateObject();
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX);
SetObjectRank(0, rank);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "teen31.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("teen31.mod", false, rank);
SetPosition(0, pos);
SetAngleY(0, angle);
SetZoom(0, zoom);
@@ -4480,8 +4346,7 @@ bool CObject::CreateTeen(Math::Vector pos, float angle, float zoom, float height
rank = m_engine->CreateObject();
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX);
SetObjectRank(0, rank);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "teen32.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("teen32.mod", false, rank);
SetPosition(0, pos);
SetAngleY(0, angle);
SetZoom(0, zoom);
@@ -4499,8 +4364,7 @@ bool CObject::CreateTeen(Math::Vector pos, float angle, float zoom, float height
rank = m_engine->CreateObject();
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX);
SetObjectRank(0, rank);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "teen33.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("teen33.mod", false, rank);
SetPosition(0, pos);
SetAngleY(0, angle);
SetZoom(0, zoom);
@@ -4514,8 +4378,7 @@ bool CObject::CreateTeen(Math::Vector pos, float angle, float zoom, float height
rank = m_engine->CreateObject();
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX);
SetObjectRank(0, rank);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "teen34.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("teen34.mod", false, rank);
SetPosition(0, pos);
SetAngleY(0, angle);
SetZoom(0, zoom);
@@ -4529,8 +4392,7 @@ bool CObject::CreateTeen(Math::Vector pos, float angle, float zoom, float height
rank = m_engine->CreateObject();
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX);
SetObjectRank(0, rank);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "teen35.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("teen35.mod", false, rank);
SetPosition(0, pos);
SetAngleY(0, angle);
SetZoom(0, zoom);
@@ -4548,8 +4410,7 @@ bool CObject::CreateTeen(Math::Vector pos, float angle, float zoom, float height
rank = m_engine->CreateObject();
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX);
SetObjectRank(0, rank);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "teen36.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("teen36.mod", false, rank);
SetPosition(0, pos);
SetAngleY(0, angle);
SetZoom(0, zoom);
@@ -4561,8 +4422,7 @@ bool CObject::CreateTeen(Math::Vector pos, float angle, float zoom, float height
rank = m_engine->CreateObject();
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX);
SetObjectRank(0, rank);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "teen37.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("teen37.mod", false, rank);
SetPosition(0, pos);
SetAngleY(0, angle);
SetZoom(0, zoom);
@@ -4574,8 +4434,7 @@ bool CObject::CreateTeen(Math::Vector pos, float angle, float zoom, float height
rank = m_engine->CreateObject();
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX);
SetObjectRank(0, rank);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "teen38a.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("teen38a.mod", false, rank);
SetPosition(0, pos);
SetAngleY(0, angle);
SetZoom(0, zoom);
@@ -4584,16 +4443,14 @@ bool CObject::CreateTeen(Math::Vector pos, float angle, float zoom, float height
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
SetObjectRank(1, rank);
SetObjectParent(1, 0);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "teen38b.mod")); // engine
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("teen38b.mod", false, rank); // engine
SetPosition(1, Math::Vector(0.0f, 30.0f, 0.0f));
rank = m_engine->CreateObject();
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
SetObjectRank(2, rank);
SetObjectParent(2, 1);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "teen38c.mod")); // propeller
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("teen38c.mod", false, rank); // propeller
SetPosition(2, Math::Vector(0.0f, 0.0f, 0.0f));
CreateCrashSphere(Math::Vector(0.0f, 2.0f, 0.0f), 10.0f, SOUND_BOUM, 0.10f);
@@ -4606,8 +4463,7 @@ bool CObject::CreateTeen(Math::Vector pos, float angle, float zoom, float height
rank = m_engine->CreateObject();
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX);
SetObjectRank(0, rank);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "teen39.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("teen39.mod", false, rank);
SetPosition(0, pos);
SetAngleY(0, angle);
SetZoom(0, zoom);
@@ -4622,8 +4478,7 @@ bool CObject::CreateTeen(Math::Vector pos, float angle, float zoom, float height
rank = m_engine->CreateObject();
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX);
SetObjectRank(0, rank);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "teen40.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("teen40.mod", false, rank);
SetPosition(0, pos);
SetAngleY(0, angle);
SetZoom(0, zoom);
@@ -4638,8 +4493,7 @@ bool CObject::CreateTeen(Math::Vector pos, float angle, float zoom, float height
rank = m_engine->CreateObject();
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX);
SetObjectRank(0, rank);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "teen41.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("teen41.mod", false, rank);
SetPosition(0, pos);
SetAngleY(0, angle);
SetZoom(0, zoom);
@@ -4650,8 +4504,7 @@ bool CObject::CreateTeen(Math::Vector pos, float angle, float zoom, float height
rank = m_engine->CreateObject();
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX);
SetObjectRank(0, rank);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "teen42.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("teen42.mod", false, rank);
SetPosition(0, pos);
SetAngleY(0, angle);
SetZoom(0, zoom);
@@ -4665,8 +4518,7 @@ bool CObject::CreateTeen(Math::Vector pos, float angle, float zoom, float height
rank = m_engine->CreateObject();
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX);
SetObjectRank(0, rank);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "teen43.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("teen43.mod", false, rank);
SetPosition(0, pos);
SetAngleY(0, angle);
SetZoom(0, zoom);
@@ -4680,8 +4532,7 @@ bool CObject::CreateTeen(Math::Vector pos, float angle, float zoom, float height
rank = m_engine->CreateObject();
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX);
SetObjectRank(0, rank);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "teen44.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("teen44.mod", false, rank);
SetPosition(0, pos);
SetAngleY(0, angle);
SetZoom(0, zoom);
@@ -4706,7 +4557,6 @@ bool CObject::CreateTeen(Math::Vector pos, float angle, float zoom, float height
pos.y += height;
SetPosition(0, pos);
- delete pModFile;
return true;
}
@@ -4715,11 +4565,10 @@ bool CObject::CreateTeen(Math::Vector pos, float angle, float zoom, float height
bool CObject::CreateQuartz(Math::Vector pos, float angle, float height,
ObjectType type)
{
- Gfx::CModelFile* pModFile;
float radius;
int rank;
- pModFile = new Gfx::CModelFile(m_iMan);
+ Gfx::CModelManager* modelManager = Gfx::CModelManager::GetInstancePointer();
SetType(type);
@@ -4728,8 +4577,7 @@ bool CObject::CreateQuartz(Math::Vector pos, float angle, float height,
rank = m_engine->CreateObject();
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_QUARTZ);
SetObjectRank(0, rank);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "quartz0.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("quartz0.mod", false, rank);
SetPosition(0, pos);
SetAngleY(0, angle);
@@ -4743,8 +4591,7 @@ bool CObject::CreateQuartz(Math::Vector pos, float angle, float height,
rank = m_engine->CreateObject();
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_QUARTZ);
SetObjectRank(0, rank);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "quartz1.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("quartz1.mod", false, rank);
SetPosition(0, pos);
SetAngleY(0, angle);
@@ -4758,8 +4605,7 @@ bool CObject::CreateQuartz(Math::Vector pos, float angle, float height,
rank = m_engine->CreateObject();
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_QUARTZ);
SetObjectRank(0, rank);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "quartz2.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("quartz2.mod", false, rank);
SetPosition(0, pos);
SetAngleY(0, angle);
@@ -4773,8 +4619,7 @@ bool CObject::CreateQuartz(Math::Vector pos, float angle, float height,
rank = m_engine->CreateObject();
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_QUARTZ);
SetObjectRank(0, rank);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "quartz3.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("quartz3.mod", false, rank);
SetPosition(0, pos);
SetAngleY(0, angle);
@@ -4817,7 +4662,6 @@ bool CObject::CreateQuartz(Math::Vector pos, float angle, float height,
m_particle->CreateParticle(pos, pos, Math::Point(2.0f, 2.0f), Gfx::PARTIQUARTZ, 0.7f+Math::Rand()*0.7f, radius, 0.0f);
m_particle->CreateParticle(pos, pos, Math::Point(2.0f, 2.0f), Gfx::PARTIQUARTZ, 0.7f+Math::Rand()*0.7f, radius, 0.0f);
- delete pModFile;
return true;
}
@@ -4826,10 +4670,9 @@ bool CObject::CreateQuartz(Math::Vector pos, float angle, float height,
bool CObject::CreateRoot(Math::Vector pos, float angle, float height,
ObjectType type)
{
- Gfx::CModelFile* pModFile;
int rank;
- pModFile = new Gfx::CModelFile(m_iMan);
+ Gfx::CModelManager* modelManager = Gfx::CModelManager::GetInstancePointer();
SetType(type);
@@ -4838,8 +4681,7 @@ bool CObject::CreateRoot(Math::Vector pos, float angle, float height,
rank = m_engine->CreateObject();
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX);
SetObjectRank(0, rank);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "root0.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("root0.mod", false, rank);
SetPosition(0, pos);
SetAngleY(0, angle);
SetZoom(0, 2.0f);
@@ -4860,8 +4702,7 @@ bool CObject::CreateRoot(Math::Vector pos, float angle, float height,
rank = m_engine->CreateObject();
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX);
SetObjectRank(0, rank);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "root1.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("root1.mod", false, rank);
SetPosition(0, pos);
SetAngleY(0, angle);
SetZoom(0, 2.0f);
@@ -4882,8 +4723,7 @@ bool CObject::CreateRoot(Math::Vector pos, float angle, float height,
rank = m_engine->CreateObject();
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX);
SetObjectRank(0, rank);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "root2.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("root2.mod", false, rank);
SetPosition(0, pos);
SetAngleY(0, angle);
SetZoom(0, 2.0f);
@@ -4903,8 +4743,7 @@ bool CObject::CreateRoot(Math::Vector pos, float angle, float height,
rank = m_engine->CreateObject();
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX);
SetObjectRank(0, rank);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "root3.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("root3.mod", false, rank);
SetPosition(0, pos);
SetAngleY(0, angle);
SetZoom(0, 2.0f);
@@ -4926,8 +4765,7 @@ bool CObject::CreateRoot(Math::Vector pos, float angle, float height,
rank = m_engine->CreateObject();
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX);
SetObjectRank(0, rank);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "root4.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("root4.mod", false, rank);
SetPosition(0, pos);
SetAngleY(0, angle);
SetZoom(0, 2.0f);
@@ -4951,8 +4789,7 @@ bool CObject::CreateRoot(Math::Vector pos, float angle, float height,
rank = m_engine->CreateObject();
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX);
SetObjectRank(0, rank);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "root4.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("root4.mod", false, rank);
SetPosition(0, pos);
SetAngleY(0, angle);
SetZoom(0, 2.0f);
@@ -4961,8 +4798,7 @@ bool CObject::CreateRoot(Math::Vector pos, float angle, float height,
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
SetObjectRank(1, rank);
SetObjectParent(1, 0);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "root5.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("root5.mod", false, rank);
SetPosition(1, Math::Vector(-5.0f, 28.0f, -4.0f));
SetAngleX(1, -30.0f*Math::PI/180.0f);
SetAngleZ(1, 20.0f*Math::PI/180.0f);
@@ -4992,7 +4828,6 @@ bool CObject::CreateRoot(Math::Vector pos, float angle, float height,
pos.y += height;
SetPosition(0, pos);
- delete pModFile;
return true;
}
@@ -5001,10 +4836,9 @@ bool CObject::CreateRoot(Math::Vector pos, float angle, float height,
bool CObject::CreateHome(Math::Vector pos, float angle, float height,
ObjectType type)
{
- Gfx::CModelFile* pModFile;
int rank;
- pModFile = new Gfx::CModelFile(m_iMan);
+ Gfx::CModelManager* modelManager = Gfx::CModelManager::GetInstancePointer();
SetType(type);
@@ -5013,8 +4847,7 @@ bool CObject::CreateHome(Math::Vector pos, float angle, float height,
rank = m_engine->CreateObject();
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX);
SetObjectRank(0, rank);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "home1.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("home1.mod", false, rank);
SetPosition(0, pos);
SetAngleY(0, angle);
SetZoom(0, 1.3f);
@@ -5034,7 +4867,6 @@ bool CObject::CreateHome(Math::Vector pos, float angle, float height,
pos.y += height;
SetPosition(0, pos);
- delete pModFile;
return true;
}
@@ -5043,10 +4875,9 @@ bool CObject::CreateHome(Math::Vector pos, float angle, float height,
bool CObject::CreateRuin(Math::Vector pos, float angle, float height,
ObjectType type)
{
- Gfx::CModelFile* pModFile;
int rank;
- pModFile = new Gfx::CModelFile(m_iMan);
+ Gfx::CModelManager* modelManager = Gfx::CModelManager::GetInstancePointer();
SetType(type);
@@ -5055,22 +4886,21 @@ bool CObject::CreateRuin(Math::Vector pos, float angle, float height,
SetObjectRank(0, rank);
std::string name;
- if ( type == OBJECT_RUINmobilew1 ) name = m_app->GetDataFilePath(DIR_MODEL, "ruin1.mod");
- if ( type == OBJECT_RUINmobilew2 ) name = m_app->GetDataFilePath(DIR_MODEL, "ruin1.mod");
- if ( type == OBJECT_RUINmobilet1 ) name = m_app->GetDataFilePath(DIR_MODEL, "ruin2.mod");
- if ( type == OBJECT_RUINmobilet2 ) name = m_app->GetDataFilePath(DIR_MODEL, "ruin2.mod");
- if ( type == OBJECT_RUINmobiler1 ) name = m_app->GetDataFilePath(DIR_MODEL, "ruin3.mod");
- if ( type == OBJECT_RUINmobiler2 ) name = m_app->GetDataFilePath(DIR_MODEL, "ruin3.mod");
- if ( type == OBJECT_RUINfactory ) name = m_app->GetDataFilePath(DIR_MODEL, "ruin4.mod");
- if ( type == OBJECT_RUINdoor ) name = m_app->GetDataFilePath(DIR_MODEL, "ruin5.mod");
- if ( type == OBJECT_RUINsupport ) name = m_app->GetDataFilePath(DIR_MODEL, "ruin6.mod");
- if ( type == OBJECT_RUINradar ) name = m_app->GetDataFilePath(DIR_MODEL, "ruin7.mod");
- if ( type == OBJECT_RUINconvert ) name = m_app->GetDataFilePath(DIR_MODEL, "ruin8.mod");
- if ( type == OBJECT_RUINbase ) name = m_app->GetDataFilePath(DIR_MODEL, "ruin9.mod");
- if ( type == OBJECT_RUINhead ) name = m_app->GetDataFilePath(DIR_MODEL, "ruin10.mod");
-
- pModFile->ReadModel(name);
- pModFile->CreateEngineObject(rank);
+ if ( type == OBJECT_RUINmobilew1 ) name = "ruin1.mod";
+ if ( type == OBJECT_RUINmobilew2 ) name = "ruin1.mod";
+ if ( type == OBJECT_RUINmobilet1 ) name = "ruin2.mod";
+ if ( type == OBJECT_RUINmobilet2 ) name = "ruin2.mod";
+ if ( type == OBJECT_RUINmobiler1 ) name = "ruin3.mod";
+ if ( type == OBJECT_RUINmobiler2 ) name = "ruin3.mod";
+ if ( type == OBJECT_RUINfactory ) name = "ruin4.mod";
+ if ( type == OBJECT_RUINdoor ) name = "ruin5.mod";
+ if ( type == OBJECT_RUINsupport ) name = "ruin6.mod";
+ if ( type == OBJECT_RUINradar ) name = "ruin7.mod";
+ if ( type == OBJECT_RUINconvert ) name = "ruin8.mod";
+ if ( type == OBJECT_RUINbase ) name = "ruin9.mod";
+ if ( type == OBJECT_RUINhead ) name = "ruin10.mod";
+
+ modelManager->AddModelReference(name, false, rank);
SetPosition(0, pos);
SetAngleY(0, angle);
@@ -5083,8 +4913,7 @@ bool CObject::CreateRuin(Math::Vector pos, float angle, float height,
SetObjectRank(6, rank);
SetObjectParent(6, 0);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "ruin1w.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("ruin1w.mod", false, rank);
SetPosition(6, Math::Vector(-3.0f, 1.8f, -4.0f));
SetAngleX(6, -Math::PI/2.0f);
@@ -5095,8 +4924,7 @@ bool CObject::CreateRuin(Math::Vector pos, float angle, float height,
SetObjectRank(7, rank);
SetObjectParent(7, 0);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "ruin1w.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("ruin1w.mod", false, rank);
SetPosition(7, Math::Vector(-3.0f, 1.0f, 3.0f));
SetAngleY(7, Math::PI-0.3f);
@@ -5108,8 +4936,7 @@ bool CObject::CreateRuin(Math::Vector pos, float angle, float height,
SetObjectRank(8, rank);
SetObjectParent(8, 0);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "ruin1w.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("ruin1w.mod", false, rank);
SetPosition(8, Math::Vector(2.0f, 1.6f, -3.0f));
SetAngleY(8, 0.3f);
@@ -5120,8 +4947,7 @@ bool CObject::CreateRuin(Math::Vector pos, float angle, float height,
SetObjectRank(9, rank);
SetObjectParent(9, 0);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "ruin1w.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("ruin1w.mod", false, rank);
SetPosition(9, Math::Vector(2.0f, 1.0f, 3.0f));
SetAngleY(9, Math::PI-0.2f);
@@ -5141,8 +4967,7 @@ bool CObject::CreateRuin(Math::Vector pos, float angle, float height,
SetObjectRank(7, rank);
SetObjectParent(7, 0);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "ruin1w.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("ruin1w.mod", false, rank);
SetPosition(7, Math::Vector(-3.0f, 1.0f, 3.0f));
SetAngleY(7, Math::PI+0.3f);
@@ -5154,8 +4979,7 @@ bool CObject::CreateRuin(Math::Vector pos, float angle, float height,
SetObjectRank(9, rank);
SetObjectParent(9, 0);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "ruin1w.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("ruin1w.mod", false, rank);
SetPosition(9, Math::Vector(2.0f, 1.0f, 3.0f));
SetAngleY(9, Math::PI+0.3f);
@@ -5175,8 +4999,7 @@ bool CObject::CreateRuin(Math::Vector pos, float angle, float height,
SetObjectRank(1, rank);
SetObjectParent(1, 0);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "ruin2c.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("ruin2c.mod", false, rank);
SetPosition(1, Math::Vector(3.0f, 5.0f, -2.5f));
SetAngleX(1, -Math::PI*0.85f);
@@ -5458,7 +5281,6 @@ bool CObject::CreateRuin(Math::Vector pos, float angle, float height,
SetAngleX(0, angle);
}
- delete pModFile;
return true;
}
@@ -5466,10 +5288,9 @@ bool CObject::CreateRuin(Math::Vector pos, float angle, float height,
bool CObject::CreateApollo(Math::Vector pos, float angle, ObjectType type)
{
- Gfx::CModelFile* pModFile;
int rank, i;
- pModFile = new Gfx::CModelFile(m_iMan);
+ Gfx::CModelManager* modelManager = Gfx::CModelManager::GetInstancePointer();
SetType(type);
@@ -5478,8 +5299,7 @@ bool CObject::CreateApollo(Math::Vector pos, float angle, ObjectType type)
rank = m_engine->CreateObject();
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX); // it is a stationary object
SetObjectRank(0, rank);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "apollol1.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("apollol1.mod", false, rank);
SetPosition(0, pos);
SetAngleY(0, angle);
SetZoom(0, 1.2f);
@@ -5491,8 +5311,7 @@ bool CObject::CreateApollo(Math::Vector pos, float angle, ObjectType type)
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
SetObjectRank(i+1, rank);
SetObjectParent(i+1, 0);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "apollol2.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("apollol2.mod", false, rank);
SetAngleY(i+1, Math::PI/2.0f*i);
}
@@ -5500,8 +5319,7 @@ bool CObject::CreateApollo(Math::Vector pos, float angle, ObjectType type)
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
SetObjectRank(5, rank);
SetObjectParent(5, 0);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "apollol3.mod")); // ladder
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("apollol3.mod", false, rank); // ladder
//? m_terrain->AddBuildingLevel(pos, 10.0f, 13.0f, 12.0f, 0.0f);
@@ -5521,8 +5339,7 @@ bool CObject::CreateApollo(Math::Vector pos, float angle, ObjectType type)
rank = m_engine->CreateObject();
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX); //it is a stationary object
SetObjectRank(0, rank);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "apolloj1.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("apolloj1.mod", false, rank);
SetPosition(0, pos);
SetAngleY(0, angle);
SetFloorHeight(0.0f);
@@ -5532,32 +5349,28 @@ bool CObject::CreateApollo(Math::Vector pos, float angle, ObjectType type)
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
SetObjectRank(1, rank);
SetObjectParent(1, 0);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "apolloj4.mod")); // wheel
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("apolloj4.mod", false, rank); // wheel
SetPosition(1, Math::Vector(-5.75f, 1.65f, -5.0f));
rank = m_engine->CreateObject();
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
SetObjectRank(2, rank);
SetObjectParent(2, 0);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "apolloj4.mod")); // wheel
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("apolloj4.mod", false, rank); // wheel
SetPosition(2, Math::Vector(-5.75f, 1.65f, 5.0f));
rank = m_engine->CreateObject();
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
SetObjectRank(3, rank);
SetObjectParent(3, 0);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "apolloj4.mod")); // wheel
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("apolloj4.mod", false, rank); // wheel
SetPosition(3, Math::Vector(5.75f, 1.65f, -5.0f));
rank = m_engine->CreateObject();
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
SetObjectRank(4, rank);
SetObjectParent(4, 0);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "apolloj4.mod")); // wheel
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("apolloj4.mod", false, rank); // wheel
SetPosition(4, Math::Vector(5.75f, 1.65f, 5.0f));
// Accessories:
@@ -5565,8 +5378,7 @@ bool CObject::CreateApollo(Math::Vector pos, float angle, ObjectType type)
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
SetObjectRank(5, rank);
SetObjectParent(5, 0);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "apolloj2.mod")); // antenna
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("apolloj2.mod", false, rank); // antenna
SetPosition(5, Math::Vector(5.5f, 8.8f, 2.0f));
SetAngleY(5, -120.0f*Math::PI/180.0f);
SetAngleZ(5, 45.0f*Math::PI/180.0f);
@@ -5575,8 +5387,7 @@ bool CObject::CreateApollo(Math::Vector pos, float angle, ObjectType type)
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
SetObjectRank(6, rank);
SetObjectParent(6, 0);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "apolloj3.mod")); // camera
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("apolloj3.mod", false, rank); // camera
SetPosition(6, Math::Vector(5.5f, 2.8f, -2.0f));
SetAngleY(6, 30.0f*Math::PI/180.0f);
@@ -5594,8 +5405,7 @@ bool CObject::CreateApollo(Math::Vector pos, float angle, ObjectType type)
rank = m_engine->CreateObject();
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX); // it is a stationary object
SetObjectRank(0, rank);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "apollof.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("apollof.mod", false, rank);
SetPosition(0, pos);
SetAngleY(0, angle);
SetFloorHeight(0.0f);
@@ -5609,8 +5419,7 @@ bool CObject::CreateApollo(Math::Vector pos, float angle, ObjectType type)
rank = m_engine->CreateObject();
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX); // it is a stationary object
SetObjectRank(0, rank);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "apollom.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("apollom.mod", false, rank);
SetPosition(0, pos);
SetAngleY(0, angle);
SetFloorHeight(0.0f);
@@ -5626,8 +5435,7 @@ bool CObject::CreateApollo(Math::Vector pos, float angle, ObjectType type)
rank = m_engine->CreateObject();
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX); // it is a stationary object
SetObjectRank(0, rank);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "apolloa.mod"));
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("apolloa.mod", false, rank);
SetPosition(0, pos);
SetAngleY(0, angle);
SetFloorHeight(0.0f);
@@ -5636,8 +5444,7 @@ bool CObject::CreateApollo(Math::Vector pos, float angle, ObjectType type)
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
SetObjectRank(1, rank);
SetObjectParent(1, 0);
- pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "apolloj2.mod")); // antenna
- pModFile->CreateEngineObject(rank);
+ modelManager->AddModelReference("apolloj2.mod", false, rank); // antenna
SetPosition(1, Math::Vector(0.0f, 5.0f, 0.0f));
SetAngleY(1, -120.0f*Math::PI/180.0f);
SetAngleZ(1, 45.0f*Math::PI/180.0f);
@@ -5651,7 +5458,6 @@ bool CObject::CreateApollo(Math::Vector pos, float angle, ObjectType type)
pos = GetPosition(0);
SetPosition(0, pos); // to display the shadows immediately
- delete pModFile;
return true;
}
diff --git a/src/object/robotmain.cpp b/src/object/robotmain.cpp
index aa2fe22..ca13efc 100644
--- a/src/object/robotmain.cpp
+++ b/src/object/robotmain.cpp
@@ -1010,7 +1010,7 @@ void CRobotMain::ChangePhase(Phase phase)
ChangePause(false);
FlushDisplayInfo();
m_engine->SetRankView(0);
- m_engine->FlushObject();
+ m_engine->DeleteAllObjects();
m_engine->SetWaterAddColor(Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f));
m_engine->SetBackground("");
m_engine->SetBackForce(false);
@@ -3673,7 +3673,7 @@ void CRobotMain::Convert()
void CRobotMain::ScenePerso()
{
DeleteAllObjects(); // removes all the current 3D Scene
- m_engine->FlushObject();
+ m_engine->DeleteAllObjects();
m_terrain->FlushRelief(); // all flat
m_terrain->FlushBuildingLevel();
m_terrain->FlushFlyingLimit();
diff --git a/src/script/script.cpp b/src/script/script.cpp
index 57d638e..f58e66d 100644
--- a/src/script/script.cpp
+++ b/src/script/script.cpp
@@ -2669,9 +2669,9 @@ CScript::CScript(CInstanceManager* iMan, CObject* object, CTaskManager** seconda
m_main = static_cast<CRobotMain*>(m_iMan->SearchInstance(CLASS_MAIN));
m_terrain = static_cast<Gfx::CTerrain*>(m_iMan->SearchInstance(CLASS_TERRAIN));
m_water = static_cast<Gfx::CWater*>(m_iMan->SearchInstance(CLASS_WATER));
- m_botProg = 0;
+ m_botProg = nullptr;
m_object = object;
- m_primaryTask = 0;
+ m_primaryTask = nullptr;
m_secondaryTask = secondaryTask;
m_interface = static_cast<Ui::CInterface*>(m_iMan->SearchInstance(CLASS_INTERFACE));
@@ -2680,7 +2680,7 @@ CScript::CScript(CInstanceManager* iMan, CObject* object, CTaskManager** seconda
m_ipf = CBOT_IPF;
m_errMode = ERM_STOP;
m_len = 0;
- m_script = 0;
+ m_script = nullptr;
m_bRun = false;
m_bStepMode = false;
m_bCompile = false;
diff --git a/src/sound/oalsound/alsound.cpp b/src/sound/oalsound/alsound.cpp
index 0201417..b8dbcda 100644
--- a/src/sound/oalsound/alsound.cpp
+++ b/src/sound/oalsound/alsound.cpp
@@ -49,9 +49,14 @@ void ALSound::CleanUp()
if (mEnabled) {
GetLogger()->Info("Unloading files and closing device...\n");
StopAll();
+
+ for (auto channel : mChannels) {
+ delete channel.second;
+ }
- for (auto item : mSounds)
+ for (auto item : mSounds) {
delete item.second;
+ }
mEnabled = false;
alutExit();
@@ -213,7 +218,7 @@ bool ALSound::SearchFreeBuffer(Sound sound, int &channel, bool &bAlreadyLoaded)
it.second->SetPriority(priority);
channel = it.first;
- bAlreadyLoaded = true;
+ bAlreadyLoaded = it.second->IsLoaded();
return true;
}
@@ -296,24 +301,31 @@ int ALSound::Play(Sound sound, Math::Vector pos, float amplitude, float frequenc
GetLogger()->Warn("Sound %d was not loaded!\n", sound);
return -1;
}
+
+ GetLogger()->Trace("ALSound::Play sound: %d volume: %f frequency: %f\n", sound, amplitude, frequency);
int channel;
bool bAlreadyLoaded;
if (!SearchFreeBuffer(sound, channel, bAlreadyLoaded))
return -1;
- if ( !bAlreadyLoaded ) {
- mChannels[channel]->SetBuffer(mSounds[sound]);
+
+ bAlreadyLoaded = false;
+ if (!bAlreadyLoaded) {
+ if (!mChannels[channel]->SetBuffer(mSounds[sound])) {
+ GetLogger()->Trace("ALSound::Play SetBuffer failed\n");
+ return -1;
+ }
}
Position(channel, pos);
// setting initial values
- mChannels[channel]->SetStartAmplitude(amplitude);
+ mChannels[channel]->SetStartAmplitude(mAudioVolume);
mChannels[channel]->SetStartFrequency(frequency);
mChannels[channel]->SetChangeFrequency(1.0f);
mChannels[channel]->ResetOper();
- mChannels[channel]->AdjustFrequency(frequency);
- mChannels[channel]->AdjustVolume(mAudioVolume);
+ mChannels[channel]->AdjustFrequency(frequency);
+ mChannels[channel]->AdjustVolume(amplitude * mAudioVolume);
mChannels[channel]->Play();
return channel;
}
@@ -451,17 +463,17 @@ void ALSound::FrameMove(float delta)
it.second->AdjustVolume(volume * mAudioVolume);
// setting frequency
- frequency = progress * (oper.finalFrequency - it.second->GetStartFrequency()) * it.second->GetStartFrequency() * it.second->GetChangeFrequency();
+ frequency = progress * abs(oper.finalFrequency - it.second->GetStartFrequency()) * it.second->GetStartFrequency() * it.second->GetChangeFrequency();
it.second->AdjustFrequency(frequency);
if (it.second->GetEnvelope().totalTime <= it.second->GetCurrentTime()) {
if (oper.nextOper == SOPER_LOOP) {
- GetLogger()->Trace("Sound oper: replay.\n");
+ GetLogger()->Trace("ALSound::FrameMove oper: replay.\n");
it.second->SetCurrentTime(0.0f);
it.second->Play();
} else {
- GetLogger()->Trace("Sound oper: next.\n");
+ GetLogger()->Trace("ALSound::FrameMove oper: next.\n");
it.second->SetStartAmplitude(oper.finalAmplitude);
it.second->SetStartFrequency(oper.finalFrequency);
it.second->PopEnvelope();
diff --git a/src/sound/oalsound/channel.cpp b/src/sound/oalsound/channel.cpp
index 2285414..e1bf202 100644
--- a/src/sound/oalsound/channel.cpp
+++ b/src/sound/oalsound/channel.cpp
@@ -36,32 +36,33 @@ Channel::Channel() {
Channel::~Channel() {
if (mReady) {
+ alSourceStop(mSource);
alSourcei(mSource, AL_BUFFER, 0);
alDeleteSources(1, &mSource);
if (alCheck())
- GetLogger()->Warn("Failed to delete sound source. Code: %s\n", alGetCode());
+ GetLogger()->Warn("Failed to delete sound source. Code: %d\n", alGetCode());
}
}
bool Channel::Play() {
- if (!mReady)
+ if (!mReady || mBuffer == nullptr)
return false;
alSourcePlay(mSource);
if (alCheck())
- GetLogger()->Warn("Could not play audio sound source. Code: %s\n", alGetCode());
+ GetLogger()->Warn("Could not play audio sound source. Code: %d\n", alGetCode());
return true;
}
bool Channel::SetPosition(Math::Vector pos) {
- if (!mReady)
+ if (!mReady || mBuffer == nullptr)
return false;
alSource3f(mSource, AL_POSITION, pos.x, pos.y, pos.z);
if (alCheck()) {
- GetLogger()->Warn("Could not set sound position. Code: %s\n", alGetCode());
+ GetLogger()->Warn("Could not set sound position. Code: %d\n", alGetCode());
return false;
}
return true;
@@ -70,12 +71,12 @@ bool Channel::SetPosition(Math::Vector pos) {
bool Channel::SetFrequency(float freq)
{
- if (!mReady)
+ if (!mReady || mBuffer == nullptr)
return false;
alSourcef(mSource, AL_PITCH, freq);
if (alCheck()) {
- GetLogger()->Warn("Could not set sound pitch. Code: %s\n", alGetCode());
+ GetLogger()->Warn("Could not set sound pitch to '%f'. Code: %d\n", freq, alGetCode());
return false;
}
return true;
@@ -85,12 +86,12 @@ bool Channel::SetFrequency(float freq)
float Channel::GetFrequency()
{
ALfloat freq;
- if (!mReady)
+ if (!mReady || mBuffer == nullptr)
return 0;
alGetSourcef(mSource, AL_PITCH, &freq);
if (alCheck()) {
- GetLogger()->Warn("Could not get sound pitch. Code: %s\n", alGetCode());
+ GetLogger()->Warn("Could not get sound pitch. Code: %d\n", alGetCode());
return 0;
}
@@ -100,12 +101,12 @@ float Channel::GetFrequency()
bool Channel::SetVolume(float vol)
{
- if (!mReady || vol < 0)
+ if (!mReady || vol < 0 || mBuffer == nullptr)
return false;
alSourcef(mSource, AL_GAIN, vol / MAXVOLUME);
if (alCheck()) {
- GetLogger()->Warn("Could not set sound volume. Code: %s\n", alGetCode());
+ GetLogger()->Warn("Could not set sound volume to '%f'. Code: %d\n", vol, alGetCode());
return false;
}
return true;
@@ -115,12 +116,12 @@ bool Channel::SetVolume(float vol)
float Channel::GetVolume()
{
ALfloat vol;
- if (!mReady)
+ if (!mReady || mBuffer == nullptr)
return 0;
alGetSourcef(mSource, AL_GAIN, &vol);
if (alCheck()) {
- GetLogger()->Warn("Could not get sound volume. Code: %s\n", alGetCode());
+ GetLogger()->Warn("Could not get sound volume. Code: %d\n", alGetCode());
return 0;
}
@@ -201,6 +202,9 @@ void Channel::ResetOper()
Sound Channel::GetSoundType() {
+ if (!mReady || mBuffer == nullptr)
+ return SOUND_NONE;
+
return mBuffer->GetSoundType();
}
@@ -213,7 +217,7 @@ bool Channel::SetBuffer(Buffer *buffer) {
mBuffer = buffer;
alSourcei(mSource, AL_BUFFER, buffer->GetBuffer());
if (alCheck()) {
- GetLogger()->Warn("Could not set sound buffer. Code: %s\n", alGetCode());
+ GetLogger()->Warn("Could not set sound buffer. Code: %d\n", alGetCode());
return false;
}
mInitFrequency = GetFrequency();
@@ -233,11 +237,12 @@ void Channel::AdjustVolume(float volume) {
bool Channel::IsPlaying() {
ALint status;
- if (!mReady) return false;
+ if (!mReady || mBuffer == nullptr)
+ return false;
alGetSourcei(mSource, AL_SOURCE_STATE, &status);
if (alCheck()) {
- GetLogger()->Warn("Could not get sound status. Code: %s\n", alGetCode());
+ GetLogger()->Warn("Could not get sound status. Code: %d\n", alGetCode());
return false;
}
@@ -249,11 +254,18 @@ bool Channel::IsReady() {
return mReady;
}
+bool Channel::IsLoaded() {
+ return mBuffer == nullptr;
+}
+
bool Channel::Stop() {
+ if (!mReady || mBuffer == nullptr)
+ return false;
+
alSourceStop(mSource);
if (alCheck()) {
- GetLogger()->Warn("Could not stop sound. Code: %s\n", alGetCode());
+ GetLogger()->Warn("Could not stop sound. Code: %d\n", alGetCode());
return false;
}
return true;
@@ -262,10 +274,13 @@ bool Channel::Stop() {
float Channel::GetCurrentTime()
{
+ if (!mReady || mBuffer == nullptr)
+ return 0.0f;
+
ALfloat current;
alGetSourcef(mSource, AL_SEC_OFFSET, &current);
if (alCheck()) {
- GetLogger()->Warn("Could not get source current play time. Code: %s\n", alGetCode());
+ GetLogger()->Warn("Could not get source current play time. Code: %d\n", alGetCode());
return 0.0f;
}
return current;
@@ -274,14 +289,20 @@ float Channel::GetCurrentTime()
void Channel::SetCurrentTime(float current)
{
+ if (!mReady || mBuffer == nullptr)
+ return;
+
alSourcef(mSource, AL_SEC_OFFSET, current);
if (alCheck())
- GetLogger()->Warn("Could not get source current play time. Code: %s\n", alGetCode());
+ GetLogger()->Warn("Could not get source current play time. Code: %d\n", alGetCode());
}
float Channel::GetDuration()
{
+ if (!mReady || mBuffer == nullptr)
+ return 0.0f;
+
return mBuffer->GetDuration();
}
diff --git a/src/sound/oalsound/channel.h b/src/sound/oalsound/channel.h
index 165ff50..5caf2b0 100644
--- a/src/sound/oalsound/channel.h
+++ b/src/sound/oalsound/channel.h
@@ -60,6 +60,7 @@ class Channel
float GetVolume();
bool IsPlaying();
bool IsReady();
+ bool IsLoaded();
bool SetBuffer(Buffer *);
bool HasEnvelope();
diff --git a/src/sound/sound.h b/src/sound/sound.h
index 566f415..a09c587 100644
--- a/src/sound/sound.h
+++ b/src/sound/sound.h
@@ -47,6 +47,7 @@
**/
enum Sound
{
+ SOUND_NONE = -1,
SOUND_CLICK = 0,
SOUND_BOUM = 1,
SOUND_EXPLO = 2,
@@ -168,7 +169,7 @@ class CSoundInterface
* Function calls \link CSoundInterface::Cache() \endlink for each file
*/
inline void CacheAll(std::string path) {
- for ( int i = 1; i < 69; i++ ) {
+ for ( int i = 1; i <= 81; i++ ) {
std::stringstream filename;
filename << path << "/sound" << std::setfill('0') << std::setw(3) << i << ".wav";
if ( !Cache(static_cast<Sound>(i), filename.str()) )
diff --git a/src/tools/CMakeLists.txt b/src/tools/CMakeLists.txt
index f6c6112..3653357 100644
--- a/src/tools/CMakeLists.txt
+++ b/src/tools/CMakeLists.txt
@@ -1,5 +1,4 @@
set(CONVERT_MODEL_SOURCES
-../common/iman.cpp
../common/logger.cpp
../common/stringutils.cpp
../graphics/engine/modelfile.cpp
diff --git a/src/tools/convert_model.cpp b/src/tools/convert_model.cpp
index a33d7d0..3eecfb1 100644
--- a/src/tools/convert_model.cpp
+++ b/src/tools/convert_model.cpp
@@ -1,4 +1,3 @@
-#include "common/iman.h"
#include "common/logger.h"
#include "graphics/engine/modelfile.h"
@@ -8,11 +7,10 @@
bool EndsWith(std::string const &fullString, std::string const &ending)
{
- if (fullString.length() >= ending.length()) {
+ if (fullString.length() >= ending.length())
return (0 == fullString.compare (fullString.length() - ending.length(), ending.length(), ending));
- } else {
+ else
return false;
- }
}
@@ -20,7 +18,6 @@ struct Args
{
bool usage;
bool dumpInfo;
- bool mirror;
std::string inputFile;
std::string outputFile;
std::string inputFormat;
@@ -30,7 +27,6 @@ struct Args
{
usage = false;
dumpInfo = false;
- mirror = false;
}
};
@@ -43,8 +39,7 @@ void PrintUsage(const std::string& program)
std::cerr << "Usage:" << std::endl;
std::cerr << std::endl;
std::cerr << " Convert files:" << std::endl;
- std::cerr << " " << program << " -i input_file -if input_format -o output_file -of output_format [-m]" << std::endl;
- std::cerr << " -m => mirror" << std::endl;
+ std::cerr << " " << program << " -i input_file -if input_format -o output_file -of output_format" << std::endl;
std::cerr << std::endl;
std::cerr << " Dump info:" << std::endl;
std::cerr << " " << program << " -d -i input_file -if input_format" << std::endl;
@@ -117,10 +112,6 @@ bool ParseArgs(int argc, char *argv[])
{
ARGS.dumpInfo = true;
}
- else if (arg == "-m")
- {
- ARGS.mirror = true;
- }
else
{
return false;
@@ -165,8 +156,7 @@ int main(int argc, char *argv[])
if (ARGS.usage)
return 0;
- CInstanceManager iMan;
- Gfx::CModelFile model(&iMan);
+ Gfx::CModelFile model;
bool ok = true;
@@ -255,9 +245,6 @@ int main(int argc, char *argv[])
return 0;
}
- if (ARGS.mirror)
- model.Mirror();
-
if (ARGS.outputFormat == "old")
{
ok = model.WriteModel(ARGS.outputFile);
diff --git a/src/ui/edit.cpp b/src/ui/edit.cpp
index e14b19d..639215a 100644
--- a/src/ui/edit.cpp
+++ b/src/ui/edit.cpp
@@ -243,7 +243,7 @@ bool CEdit::EventProcess(const Event &event)
Scroll(m_lineFirst-3, true);
return true;
}
- if (event.type == EVENT_KEY_DOWN &&
+ if (event.type == EVENT_MOUSE_WHEEL &&
event.mouseWheel.dir == WHEEL_DOWN &&
Detect(event.mousePos) )
{
@@ -282,7 +282,7 @@ bool CEdit::EventProcess(const Event &event)
}
}
- if ( m_scroll != 0 && !m_bGeneric )
+ if ( m_scroll != nullptr && !m_bGeneric )
{
m_scroll->EventProcess(event);
@@ -1248,7 +1248,7 @@ void CEdit::SetText(const char *text, bool bNew)
{
int i, j, font;
bool bBOL;
-
+
if ( !bNew ) UndoMemorize(OPERUNDO_SPEC);
m_len = strlen(text);
@@ -2172,11 +2172,11 @@ void CEdit::Scroll()
{
float value;
- if ( m_scroll != 0 )
+ if ( m_scroll != nullptr )
{
value = m_scroll->GetVisibleValue();
- value *= m_lineTotal-m_lineVisible;
- Scroll(static_cast<int>(value+0.5f), true);
+ value *= m_lineTotal - m_lineVisible;
+ Scroll(static_cast<int>(value + 0.5f), true);
}
}
@@ -3048,7 +3048,7 @@ bool CEdit::MinMaj(bool bMaj)
void CEdit::Justif()
{
- float width, value, size, indentLength;
+ float width, size, indentLength;
int i, j, line, indent;
bool bDual, bString, bRem;
@@ -3176,26 +3176,7 @@ void CEdit::Justif()
m_lineFirst = 0;
}
- if ( m_scroll != 0 )
- {
- if ( m_lineTotal <= m_lineVisible )
- {
- m_scroll->SetVisibleRatio(1.0f);
- m_scroll->SetVisibleValue(0.0f);
- m_scroll->SetArrowStep(0.0f);
- }
- else
- {
- value = static_cast<float>(m_lineVisible/m_lineTotal);
- m_scroll->SetVisibleRatio(value);
-
- value = static_cast<float>(m_lineFirst/(m_lineTotal-m_lineVisible));
- m_scroll->SetVisibleValue(value);
-
- value = static_cast<float>(1.0f/(m_lineTotal-m_lineVisible));
- m_scroll->SetArrowStep(value);
- }
- }
+ UpdateScroll();
m_timeBlink = 0.0f; // lights the cursor immediately
}
@@ -3326,5 +3307,30 @@ bool CEdit::SetFormat(int cursor1, int cursor2, int format)
return true;
}
+void CEdit::UpdateScroll()
+{
+ float value;
+
+ if ( m_scroll != nullptr )
+ {
+ if ( m_lineTotal <= m_lineVisible )
+ {
+ m_scroll->SetVisibleRatio(1.0f);
+ m_scroll->SetVisibleValue(0.0f);
+ m_scroll->SetArrowStep(0.0f);
+ }
+ else
+ {
+ value = static_cast<float>(m_lineVisible) / m_lineTotal;
+ m_scroll->SetVisibleRatio(value);
+
+ value = static_cast<float>(m_lineFirst) / (m_lineTotal - m_lineVisible);
+ m_scroll->SetVisibleValue(value);
+
+ value = 1.0f / (m_lineTotal - m_lineVisible);
+ m_scroll->SetArrowStep(value);
+ }
+ }
+}
}
diff --git a/src/ui/edit.h b/src/ui/edit.h
index 35d8b2c..7247181 100644
--- a/src/ui/edit.h
+++ b/src/ui/edit.h
@@ -234,6 +234,8 @@ protected:
void UndoFlush();
void UndoMemorize(OperUndo oper);
bool UndoRecall();
+
+ void UpdateScroll();
protected:
CScroll* m_scroll; // vertical scrollbar on the right
diff --git a/src/ui/test/CMakeLists.txt b/src/ui/test/CMakeLists.txt
index e411067..c38d2bb 100644
--- a/src/ui/test/CMakeLists.txt
+++ b/src/ui/test/CMakeLists.txt
@@ -3,7 +3,6 @@ cmake_minimum_required(VERSION 2.8)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE debug)
endif(NOT CMAKE_BUILD_TYPE)
-set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wold-style-cast -std=gnu++0x")
set(CMAKE_CXX_FLAGS_DEBUG "-g -O0")
include_directories(
diff --git a/tools/blender-scripts.py b/tools/blender-scripts.py
index 6591393..ed515b4 100644
--- a/tools/blender-scripts.py
+++ b/tools/blender-scripts.py
@@ -38,10 +38,7 @@ class ColobotVertex:
return 1
def __eq__(self, other):
- return fuzzy_equal_v(self.coord, other.coord) and
- fuzzy_equal_v(self.normal, other.normal) and
- fuzzy_equal_v(self.t1, other.t1) and
- fuzzy_equal_v(self.t2, other.t2)
+ return fuzzy_equal_v(self.coord, other.coord) and fuzzy_equal_v(self.normal, other.normal) and fuzzy_equal_v(self.t1, other.t1) and fuzzy_equal_v(self.t2, other.t2)
class ColobotMaterial:
"""Material as saved in Colobot model file"""
@@ -56,11 +53,7 @@ class ColobotMaterial:
return 1
def __eq__(self, other):
- return fuzzy_equal_v(self.diffuse, other.diffuse) and
- fuzzy_equal_v(self.ambient, other.ambient) and
- fuzzy_equal_v(self.specular, other.specular) and
- self.tex1 == other.tex1 and
- self.tex2 == other.tex2
+ return fuzzy_equal_v(self.diffuse, other.diffuse) and fuzzy_equal_v(self.ambient, other.ambient) and fuzzy_equal_v(self.specular, other.specular) and self.tex1 == other.tex1 and self.tex2 == other.tex2
class ColobotTriangle:
"""Triangle as saved in Colobot model file"""