after playing around with the Irrlicht examples I noticed that on my Linux machine the FPS camera makes very choppy movements when i use the mouse to "look around".
I tested the example (see below) on my Linux machine and on my Windows Notebook. On my Windows Notebook the camera movement is perfectly smooth. But that's not all yet: If I run the example on Linux with valgrind (which I use for mem-checking) the camera movements are also perfectly smooth.
This brings me to the assumption, that the problem might be a frames-rate issue, since valgrind usually slows down the performance.
I found this thread on the forums, but it seems a bit outdated, since there is no CCameraFPSSceneNode class but a CSceneNodeAnimatorCameraFPS class that handels the movement.
Have you ever expierenced something similar? Or do you know what's the problem here?
Thanks in advance!
Regards
--------------------------------------------------------------------------------------------------
PS: Here is the code example "src/main.cpp" and also the Makefile "makefile"
To run the example you will also need the quake3 map package file "map-20kdm2.pk3" from the Irrlicht examples.
The structure for this example must be:
- Makefile
- src/main.cpp
- media/map-20kdm2.pk3
- make: Build example
- make run: Run example (also builds the example, if necessary)
- make mcf: Run example with valgrind (only works on Linux)
Code: Select all
/*******************************************************************************
* Irrlicht FPS camera example
******************************************************************************/
#include <iostream>
#include <exception>
#include <irrlicht/irrlicht.h>
using namespace irr;
/* -------------------------------------------------------------------------- */
/* custom message exception */
class ECustomMessageException : public std::exception
{
public:
ECustomMessageException(const std::string& msg) throw() :
message(msg) {};
virtual ~ECustomMessageException() throw() {};
virtual const char* what() const throw()
{
return message.c_str();
}
protected:
std::string message;
};
/* -------------------------------------------------------------------------- */
/* global variables - to make the example quick and dirty */
IrrlichtDevice* device = NULL;
video::IVideoDriver* driver = NULL;
scene::ISceneManager* scenemgr = NULL;
/* -------------------------------------------------------------------------- */
void loadMap(const io::path& map_package_filename, const io::path& map_name, const core::vector3df& position)
{
scene::IAnimatedMesh* map_mesh = NULL;
scene::IMeshSceneNode* map_node = NULL;
device->getFileSystem()->addFileArchive(map_package_filename);
map_mesh = scenemgr->getMesh(map_name);
if (map_mesh)
{
map_node = scenemgr->addOctreeSceneNode(map_mesh->getMesh(0), 0, -1, 1024);
if (map_node)
map_node->setPosition(position);
else
throw ECustomMessageException(
"Failed to add map mesh as scene node to the scene manager");
}
else
throw ECustomMessageException("Unable to load map file");
}
void setupCamera()
{
device->getCursorControl()->setVisible(false);
scenemgr->addCameraSceneNodeFPS(NULL, 100.0f, 0.3f);
}
int main(int argc, char* argv[])
{
/* define initial return value */
int exit_code = 0;
try
{
/* setup irrlicht and global variables */
device = createDevice(video::EDT_OPENGL, core::dimension2du(800, 600), 16, false, false, false);
driver = device->getVideoDriver();
scenemgr = device->getSceneManager();
/* setup fps camera */
setupCamera();
/* load quake3 map */
loadMap("media/map-20kdm2.pk3", "20kdm2.bsp", core::vector3df(-1350,-130,-1400));
/* main game loop */
while(device->run())
{
driver->beginScene(true, true, video::SColor(128, 128, 128, 140));
scenemgr->drawAll();
driver->endScene();
}
/* cleanup */
device->drop();
exit_code = 0;
}
catch (const std::exception& e)
{
exit_code = -1;
std::cerr << "FATAL ERROR: [" << e.what() << "]" << std::endl;
}
return exit_code;
}
Code: Select all
################################################################################
# irrlicht_test -- Test for the irrlicht library
################################################################################
TARGET := irrlicht_test
ifeq ($(OS), Windows_NT)
TARGET := $(TARGET).exe
endif
SRC_DIR := src
INC_DIR := src
OBJ_DIR := obj
SOURCES := main.cpp
OBJECTS := $(SOURCES:%.cpp=%.o)
OBJ := $(OBJECTS:%=$(OBJ_DIR)/%)
CXXFLAGS_COMMON := -Wall -pedantic-errors -std=c++11 -I$(INC_DIR)
CXXFLAGS := -g $(CXXFLAGS_COMMON) -D DEBUG
CXXFLAGS_RELEASE := $(CXXFLAGS_COMMON)
LDFLAGS := -lIrrlicht
MKDIR := mkdir -p
GDB := gdb
VALGRIND := valgrind
VALGRIND_OPTIONS := --tool=memcheck
ifeq ($(OS), Windows_NT)
CXX := x86_64-w64-mingw32-g++
endif
# ------------------------------------------------------------------------------
# BUILD (main target)
# default target
default: debug
debug: build
release: CXXFLAGS := $(CXXFLAGS_RELEASE)
release: build
build: object_dir $(TARGET)
$(TARGET): $(OBJ)
$(CXX) -o $@ $^ $(LDFLAGS)
# build object files
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.cpp
$(CXX) $(CXXFLAGS) -o $@ -c $<
# create object file directory
object_dir: $(OBJ_DIR)/
$(OBJ_DIR)/:
$(MKDIR) $@
.PHONY: default debug release build object_dir
# ------------------------------------------------------------------------------
# EXECUTION
# execution of main target
run: build
@./$(TARGET)
rund: rundebug
rundebug: build
$(GDB) ./$(TARGET)
.PHONY: run rund rundebug
# ------------------------------------------------------------------------------
# MEMORY-CHECK
# memory-check for main target
mc: memcheck
memcheck: build
$(VALGRIND) $(VALGRIND_OPTIONS) ./$(TARGET)
mcf: memcheck-full
memcheck-full: VALGRIND_OPTIONS := $(VALGRIND_OPTIONS) --leak-check=full
memcheck-full: build
$(VALGRIND) $(VALGRIND_OPTIONS) ./$(TARGET)
.PHONY: mc memcheck mcf memcheck-full
# ------------------------------------------------------------------------------
# CLEANUP
# cleanup main target
clean:
$(RM) $(TARGET) $(OBJ)
rebuild: clean default
.PHONY: clean rebuild