Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Colour picking uses prng sequence; Option to disable G3D interpolation #2

Merged
merged 1 commit into from Nov 29, 2013
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -430,8 +430,6 @@ Game::~Game() {

world.end(); //must die before selection because of referencers

BaseColorPickEntity::resetUniqueColors();

if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] aiInterfaces.size() = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,aiInterfaces.size());

delete videoPlayer;
@@ -1003,8 +1001,6 @@ void Game::load(int loadTypes) {
SoundRenderer &soundRenderer= SoundRenderer::getInstance();
soundRenderer.stopAllSounds(fadeMusicMilliseconds);

BaseColorPickEntity::resetUniqueColors();

Config &config = Config::getInstance();
Logger &logger= Logger::getInstance();

@@ -2612,7 +2608,6 @@ void Game::update() {
aiInterfaces.clear();
gui.end(); //selection must be cleared before deleting units
world.end(); //must die before selection because of referencers
BaseColorPickEntity::resetUniqueColors();
// MUST DO THIS LAST!!!! Because objects above have pointers to things like
// unit particles and fade them out etc and this end method deletes the original
// object pointers.
@@ -2637,7 +2632,6 @@ void Game::update() {
soundRenderer.stopAllSounds(fadeMusicMilliseconds);

world.endScenario();
BaseColorPickEntity::resetUniqueColors();

Renderer &renderer= Renderer::getInstance();
renderer.endScenario();
@@ -54,6 +54,7 @@
#include "string_utils.h"
#include "auto_test.h"
#include "lua_script.h"
#include "interpolation.h"

// To handle signal catching
#if defined(__GNUC__) && !defined(__MINGW32__) && !defined(__FreeBSD__) && !defined(BSD)
@@ -4636,8 +4637,14 @@ int glestMain(int argc, char** argv) {
// Explicitly disable VBO's
if(config.getBool("DisableVBO","false") == true || hasCommandArgument(argc, argv,GAME_ARGS[GAME_ARG_DISABLE_VBO]) == true) {
setVBOSupported(false);
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("**WARNING** Disabling VBO's\n");
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("**INFO** Disabling VBOs\n");
}

if(config.getBool("DisableVertexInterpolation","false") || hasCommandArgument(argc, argv, GAME_ARGS[GAME_ARG_DISABLE_VERTEX_INTERPOLATION])) {
InterpolationData::setEnableInterpolation(false);
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("**INFO** Disabling Interpolation\n");
}


if(config.getBool("EnableVSynch","false") == true) {
::Shared::Platform::Window::setTryVSynch(true);
@@ -79,7 +79,6 @@ Object::~Object() {
delete resource;
resource = NULL;

recycleUniqueColor();
}

void Object::end() {
@@ -584,8 +584,6 @@ Unit::~Unit() {
delete mutexCommands;
mutexCommands=NULL;

recycleUniqueColor();

#ifdef LEAK_CHECK_UNITS
Unit::mapMemoryList.erase(this);
#endif
@@ -30,21 +30,20 @@ class InterpolationData{
Vec3f *vertices;
Vec3f *normals;

//std::map<std::string, Vec3f *> cacheVertices;
//std::map<std::string, Vec3f *> cacheNormals;
int raw_frame_ofs;

std::map<float, std::map<bool, Vec3f *> > cacheVertices;
std::map<float, std::map<bool, Vec3f *> > cacheNormals;
static bool enableCache;
static bool enableInterpolation;

void update(const Vec3f* src, Vec3f* &dest, float t, bool cycle);

public:
InterpolationData(const Mesh *mesh);
~InterpolationData();

static void setEnableCache(bool enabled) { enableCache = enabled; }
static void setEnableInterpolation(bool enabled) { enableInterpolation = enabled; }

const Vec3f *getVertices() const {return vertices==NULL? mesh->getVertices(): vertices;}
const Vec3f *getNormals() const {return normals==NULL? mesh->getNormals(): normals;}
const Vec3f *getVertices() const {return !vertices || !enableInterpolation? mesh->getVertices()+raw_frame_ofs: vertices;}
const Vec3f *getNormals() const {return !normals || !enableInterpolation? mesh->getNormals()+raw_frame_ofs: normals;}

void update(float t, bool cycle);
void updateVertices(float t, bool cycle);
@@ -275,18 +275,11 @@ class BaseColorPickEntity {
string getColorDescription() const;
virtual string getUniquePickName() const = 0;

static void resetUniqueColors();

protected:

void recycleUniqueColor();

private:
unsigned char uniqueColorID[COLOR_COMPONENTS];

static unsigned char nextColorID[COLOR_COMPONENTS];
static vector<vector<unsigned char> > nextColorIDReuseList;
static map<string,bool> usedColorIDList;
static int nextColorID;
static const int k, p;
static Mutex mutexNextColorID;

static auto_ptr<PixelBufferWrapper> pbo;
@@ -73,6 +73,7 @@ const char *GAME_ARGS[] = {
"--disable-backtrace",
"--disable-sigsegv-handler",
"--disable-vbo",
"--disable-vertex-interpolation",
"--disable-sound",
"--enable-legacyfonts",
"--force-ftglfonts",
@@ -152,6 +153,7 @@ enum GAME_ARG_TYPE {
GAME_ARG_DISABLE_BACKTRACE,
GAME_ARG_DISABLE_SIGSEGV_HANDLER,
GAME_ARG_DISABLE_VBO,
GAME_ARG_DISABLE_VERTEX_INTERPOLATION,
GAME_ARG_DISABLE_SOUND,
GAME_ARG_ENABLE_LEGACYFONTS,
GAME_ARG_FORCE_FTGLFONTS,
@@ -426,6 +428,7 @@ void printParameterHelp(const char *argv0, bool foundInvalidArgs) {


printf("\n%s\t\t\tdisables trying to use Vertex Buffer Objects.",GAME_ARGS[GAME_ARG_DISABLE_VBO]);
printf("\n%s\t\t\tdisables interpolating animations to make them smoother.",GAME_ARGS[GAME_ARG_DISABLE_VERTEX_INTERPOLATION]);
printf("\n%s\t\t\tdisables the sound system.",GAME_ARGS[GAME_ARG_DISABLE_SOUND]);

printf("\n%s\t\tenables using the legacy font system.",GAME_ARGS[GAME_ARG_ENABLE_LEGACYFONTS]);
@@ -30,7 +30,7 @@ namespace Shared{ namespace Graphics{
// class InterpolationData
// =====================================================

bool InterpolationData::enableCache = false;
bool InterpolationData::enableInterpolation = true;

InterpolationData::InterpolationData(const Mesh *mesh) {
if(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == true) {
@@ -40,40 +40,16 @@ InterpolationData::InterpolationData(const Mesh *mesh) {
vertices= NULL;
normals= NULL;

raw_frame_ofs = 0;

this->mesh= mesh;

if(mesh->getFrameCount()>1) {
vertices= new Vec3f[mesh->getVertexCount()];
normals= new Vec3f[mesh->getVertexCount()];
}

cacheVertices.clear();
cacheNormals.clear();
}

InterpolationData::~InterpolationData(){
delete [] vertices;
vertices=NULL;
delete [] normals;
normals=NULL;

for(std::map<float, std::map<bool, Vec3f *> >::iterator iterVert = cacheVertices.begin();
iterVert != cacheVertices.end(); ++iterVert) {
for(std::map<bool, Vec3f *>::iterator iterVert2 = iterVert->second.begin();
iterVert2 != iterVert->second.end(); ++iterVert2) {
delete [] iterVert2->second;
}
}
cacheVertices.clear();

for(std::map<float, std::map<bool, Vec3f *> >::iterator iterVert = cacheNormals.begin();
iterVert != cacheNormals.end(); ++iterVert) {
for(std::map<bool, Vec3f *>::iterator iterVert2 = iterVert->second.begin();
iterVert2 != iterVert->second.end(); ++iterVert2) {
delete [] iterVert2->second;
}
}
cacheNormals.clear();
}

void InterpolationData::update(float t, bool cycle){
@@ -82,6 +58,15 @@ void InterpolationData::update(float t, bool cycle){
}

void InterpolationData::updateVertices(float t, bool cycle) {
update(mesh->getVertices(), vertices, t, cycle);
}

void InterpolationData::updateNormals(float t, bool cycle) {
update(mesh->getNormals(), normals, t, cycle);
}

void InterpolationData::update(const Vec3f* src, Vec3f* &dest, float t, bool cycle) {

if(t <0.0f || t>1.0f) {
printf("ERROR t = [%f] for cycle [%d] f [%d] v [%d]\n",t,cycle,mesh->getFrameCount(),mesh->getVertexCount());
}
@@ -96,20 +81,6 @@ void InterpolationData::updateVertices(float t, bool cycle) {
uint32 vertexCount= mesh->getVertexCount();

if(frameCount > 1) {
if(enableCache == true) {
std::map<float, std::map<bool, Vec3f *> >::iterator iterFind = cacheVertices.find(t);
if(iterFind != cacheVertices.end()) {
std::map<bool, Vec3f *>::iterator iterFind2 = iterFind->second.find(cycle);
if(iterFind2 != iterFind->second.end()) {
memcpy(vertices,iterFind2->second,sizeof(Vec3f) * vertexCount);
return;
}
}
cacheVertices[t][cycle] = new Vec3f[vertexCount];
}

const Vec3f *meshVertices= mesh->getVertices();

//misc vars
uint32 prevFrame;
uint32 nextFrame;
@@ -133,74 +104,16 @@ void InterpolationData::updateVertices(float t, bool cycle) {
//assertions
assert(prevFrame<frameCount);
assert(nextFrame<frameCount);

//interpolate vertices
for(uint32 j=0; j<vertexCount; ++j){
vertices[j]= meshVertices[prevFrameBase+j].lerp(localT, meshVertices[nextFrameBase+j]);

if(enableCache == true) {
cacheVertices[t][cycle][j] = vertices[j];

if(enableInterpolation) {
if(!dest) { // not previously allocated
dest = new Vec3f[vertexCount];
}
}
}
}

void InterpolationData::updateNormals(float t, bool cycle){
if(t < 0.0f || t > 1.0f) {
throw megaglest_runtime_error("t < 0.0f || t > 1.0f t = [" + floatToStr(t,16) + "]");

assert(t>=0.0f && t<=1.0f);
}

uint32 frameCount= mesh->getFrameCount();
uint32 vertexCount= mesh->getVertexCount();

if(frameCount > 1) {
if(enableCache == true) {
std::map<float, std::map<bool, Vec3f *> >::iterator iterFind = cacheNormals.find(t);
if(iterFind != cacheNormals.end()) {
std::map<bool, Vec3f *>::iterator iterFind2 = iterFind->second.find(cycle);
if(iterFind2 != iterFind->second.end()) {
memcpy(normals,iterFind2->second,sizeof(Vec3f) * vertexCount);
return;
}
}
cacheNormals[t][cycle] = new Vec3f[vertexCount];
}

const Vec3f *meshNormals= mesh->getNormals();

//misc vars
uint32 prevFrame;
uint32 nextFrame;
float localT;

if(cycle == true) {
prevFrame= min<uint32>(static_cast<uint32>(t*frameCount), frameCount-1);
nextFrame= (prevFrame+1) % frameCount;
localT= t*frameCount - prevFrame;
}
else {
prevFrame= min<uint32> (static_cast<uint32> (t * (frameCount-1)), frameCount - 2);
nextFrame= min(prevFrame + 1, frameCount - 1);
localT= t * (frameCount-1) - prevFrame;
//printf(" prevFrame=%d nextFrame=%d localT=%f\n",prevFrame,nextFrame,localT);
}

uint32 prevFrameBase= prevFrame*vertexCount;
uint32 nextFrameBase= nextFrame*vertexCount;

//assertions
assert(prevFrame<frameCount);
assert(nextFrame<frameCount);

//interpolate vertices
for(uint32 j=0; j<vertexCount; ++j){
normals[j]= meshNormals[prevFrameBase+j].lerp(localT, meshNormals[nextFrameBase+j]);

if(enableCache == true) {
cacheNormals[t][cycle][j] = normals[j];
for(uint32 j=0; j<vertexCount; ++j){
dest[j]= src[prevFrameBase+j].lerp(localT, src[nextFrameBase+j]);
}
} else {
raw_frame_ofs = prevFrameBase;
}
}
}