mirror of
https://github.com/glest/glest-source.git
synced 2025-08-19 14:41:23 +02:00
- improved performance and bug fixes.
This commit is contained in:
@@ -15,6 +15,7 @@
|
||||
#include <string>
|
||||
#include "vec.h"
|
||||
#include "types.h"
|
||||
#include <map>
|
||||
#include "leak_dumper.h"
|
||||
|
||||
using std::string;
|
||||
@@ -160,7 +161,6 @@ protected:
|
||||
int components;
|
||||
uint8 *pixels;
|
||||
string path;
|
||||
|
||||
public:
|
||||
//constructor & destructor
|
||||
Pixmap2D();
|
||||
|
@@ -124,8 +124,8 @@ protected:
|
||||
public:
|
||||
void load(const string &path);
|
||||
|
||||
Pixmap2D *getPixmap() {return &pixmap;}
|
||||
const Pixmap2D *getPixmap() const {return &pixmap;}
|
||||
Pixmap2D *getPixmap() {return &pixmap;}
|
||||
const Pixmap2D *getPixmapConst() const {return &pixmap;}
|
||||
virtual string getPath() const;
|
||||
virtual void deletePixels();
|
||||
virtual uint64 getPixelByteCount() const {return pixmap.getPixelByteCount();}
|
||||
|
@@ -68,19 +68,25 @@ private:
|
||||
Uint32 freq;
|
||||
bool stopped;
|
||||
|
||||
Uint32 lastStartCount;
|
||||
Uint32 lastTickCount;
|
||||
int64 lastResult;
|
||||
int lastMultiplier;
|
||||
bool lastStopped;
|
||||
|
||||
public:
|
||||
Chrono();
|
||||
void start();
|
||||
void stop();
|
||||
int64 getMicros() const;
|
||||
int64 getMillis() const;
|
||||
int64 getSeconds() const;
|
||||
int64 getMicros();
|
||||
int64 getMillis();
|
||||
int64 getSeconds();
|
||||
|
||||
static int64 getCurTicks();
|
||||
static int64 getCurMillis();
|
||||
|
||||
private:
|
||||
int64 queryCounter(int multiplier) const;
|
||||
int64 queryCounter(int multiplier);
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
|
@@ -180,8 +180,10 @@ void ParticleSystem::setVisible(bool visible){
|
||||
}
|
||||
|
||||
// =============== MISC =========================
|
||||
void ParticleSystem::fade(){
|
||||
assert(state==sPlay);
|
||||
void ParticleSystem::fade() {
|
||||
if(particleObserver != NULL) {
|
||||
assert(state == sPlay);
|
||||
}
|
||||
state= sFade;
|
||||
if(particleObserver!=NULL){
|
||||
particleObserver->update(this);
|
||||
|
@@ -781,50 +781,58 @@ Vec3f Pixmap2D::getPixel3f(int x, int y) const {
|
||||
}
|
||||
|
||||
float Pixmap2D::getPixelf(int x, int y) const {
|
||||
return pixels[(w*y+x)*components]/255.f;
|
||||
int index = (w*y+x)*components;
|
||||
return pixels[index]/255.f;
|
||||
}
|
||||
|
||||
float Pixmap2D::getComponentf(int x, int y, int component) const {
|
||||
float c;
|
||||
float c=0;
|
||||
getComponent(x, y, component, c);
|
||||
return c;
|
||||
}
|
||||
|
||||
void Pixmap2D::setPixel(int x, int y, const uint8 *value) {
|
||||
for(int i=0; i<components; ++i) {
|
||||
pixels[(w*y+x)*components+i]= value[i];
|
||||
int index = (w*y+x)*components+i;
|
||||
pixels[index]= value[i];
|
||||
}
|
||||
}
|
||||
|
||||
void Pixmap2D::setPixel(int x, int y, const float32 *value) {
|
||||
for(int i=0; i<components; ++i) {
|
||||
pixels[(w*y+x)*components+i]= static_cast<uint8>(value[i]*255.f);
|
||||
int index = (w*y+x)*components+i;
|
||||
pixels[index]= static_cast<uint8>(value[i]*255.f);
|
||||
}
|
||||
}
|
||||
|
||||
void Pixmap2D::setComponent(int x, int y, int component, uint8 value) {
|
||||
pixels[(w*y+x)*components+component]= value;
|
||||
int index = (w*y+x)*components+component;
|
||||
pixels[index] = value;
|
||||
}
|
||||
|
||||
void Pixmap2D::setComponent(int x, int y, int component, float32 value){
|
||||
pixels[(w*y+x)*components+component]= static_cast<uint8>(value*255.f);
|
||||
void Pixmap2D::setComponent(int x, int y, int component, float32 value) {
|
||||
int index = (w*y+x)*components+component;
|
||||
pixels[index]= static_cast<uint8>(value*255.f);
|
||||
}
|
||||
|
||||
//vector set
|
||||
void Pixmap2D::setPixel(int x, int y, const Vec3f &p){
|
||||
for(int i=0; i<components && i<3; ++i){
|
||||
pixels[(w*y+x)*components+i]= static_cast<uint8>(p.ptr()[i]*255.f);
|
||||
void Pixmap2D::setPixel(int x, int y, const Vec3f &p) {
|
||||
for(int i = 0; i < components && i < 3; ++i) {
|
||||
int index = (w*y+x)*components+i;
|
||||
pixels[index]= static_cast<uint8>(p.ptr()[i]*255.f);
|
||||
}
|
||||
}
|
||||
|
||||
void Pixmap2D::setPixel(int x, int y, const Vec4f &p){
|
||||
for(int i=0; i<components && i<4; ++i){
|
||||
pixels[(w*y+x)*components+i]= static_cast<uint8>(p.ptr()[i]*255.f);
|
||||
void Pixmap2D::setPixel(int x, int y, const Vec4f &p) {
|
||||
for(int i = 0; i < components && i < 4; ++i) {
|
||||
int index = (w*y+x)*components+i;
|
||||
pixels[index]= static_cast<uint8>(p.ptr()[i]*255.f);
|
||||
}
|
||||
}
|
||||
|
||||
void Pixmap2D::setPixel(int x, int y, float p){
|
||||
pixels[(w*y+x)*components]= static_cast<uint8>(p*255.f);
|
||||
void Pixmap2D::setPixel(int x, int y, float p) {
|
||||
int index = (w*y+x)*components;
|
||||
pixels[index]= static_cast<uint8>(p*255.f);
|
||||
}
|
||||
|
||||
void Pixmap2D::setPixels(const uint8 *value){
|
||||
|
@@ -108,6 +108,12 @@ Chrono::Chrono() {
|
||||
freq = 1000;
|
||||
stopped= true;
|
||||
accumCount= 0;
|
||||
|
||||
lastStartCount = 0;
|
||||
lastTickCount = 0;
|
||||
lastResult = 0;
|
||||
lastMultiplier = 0;
|
||||
lastStopped = false;
|
||||
}
|
||||
|
||||
void Chrono::start() {
|
||||
@@ -122,26 +128,51 @@ void Chrono::stop() {
|
||||
stopped= true;
|
||||
}
|
||||
|
||||
int64 Chrono::getMicros() const {
|
||||
int64 Chrono::getMicros() {
|
||||
return queryCounter(1000000);
|
||||
}
|
||||
|
||||
int64 Chrono::getMillis() const {
|
||||
int64 Chrono::getMillis() {
|
||||
return queryCounter(1000);
|
||||
}
|
||||
|
||||
int64 Chrono::getSeconds() const {
|
||||
int64 Chrono::getSeconds() {
|
||||
return queryCounter(1);
|
||||
}
|
||||
|
||||
int64 Chrono::queryCounter(int multiplier) const {
|
||||
if(stopped) {
|
||||
return multiplier*accumCount/freq;
|
||||
} else {
|
||||
Uint32 endCount;
|
||||
endCount = SDL_GetTicks();
|
||||
return multiplier*(accumCount+endCount-startCount)/freq;
|
||||
int64 Chrono::queryCounter(int multiplier) {
|
||||
|
||||
if( multiplier == lastMultiplier &&
|
||||
stopped == lastStopped &&
|
||||
lastStartCount == startCount) {
|
||||
|
||||
if(stopped) {
|
||||
return lastResult;
|
||||
}
|
||||
else {
|
||||
Uint32 endCount = SDL_GetTicks();
|
||||
if(lastTickCount == endCount) {
|
||||
return lastResult;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int64 result = 0;
|
||||
if(stopped) {
|
||||
result = multiplier*accumCount/freq;
|
||||
}
|
||||
else {
|
||||
Uint32 endCount = SDL_GetTicks();
|
||||
result = multiplier*(accumCount+endCount-startCount)/freq;
|
||||
lastTickCount = endCount;
|
||||
}
|
||||
|
||||
lastStartCount = startCount;
|
||||
lastResult = result;
|
||||
lastMultiplier = multiplier;
|
||||
lastStopped = stopped;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
int64 Chrono::getCurMillis() {
|
||||
|
Reference in New Issue
Block a user