Something went wrong. Try again.
the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
Something went wrong. Try again.
7.4 kB · 355 lines
C++
at main
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355#include "stdafx.h"#include "Texture.h"#include "..\Minecraft.World\StringHelpers.h"#include "ClockTexture.h"#include "CompassTexture.h"#include "StitchedTexture.h"#include "TextureManager.h"
StitchedTexture *StitchedTexture::create(const wstring &name){ // TODO: Generalize? if (name.compare(L"clock") == 0) { return new ClockTexture(); } else if (name.compare(L"compass") == 0) { return new CompassTexture(); } else { return new StitchedTexture(name,name); }}
StitchedTexture::StitchedTexture(const wstring &name, const wstring &filename) : name(name){ // 4J Initialisers source = NULL; rotated = false; x = 0; y = 0; width = 0; height = 0; u0 = 0.0f; u1 = 0.0f; v0 = 0.0f; v1 = 0.0f; widthTranslation = 0.0f; heightTranslation = 0.0f; frame = 0; subFrame = 0; frameOverride = NULL; flags = 0; frames = NULL; m_fileName = filename;}
void StitchedTexture::freeFrameTextures(){ if( frames ) { for(AUTO_VAR(it, frames->begin()); it != frames->end(); ++it) { TextureManager::getInstance()->unregisterTexture(L"", *it); delete *it; } delete frames; }}
StitchedTexture::~StitchedTexture(){ for(AUTO_VAR(it, frames->begin()); it != frames->end(); ++it) { delete *it; } delete frames;}
void StitchedTexture::initUVs(float U0, float V0, float U1, float V1){ u0 = U0; u1 = U1; v0 = V0; v1 = V1;}
void StitchedTexture::init(Texture *source, vector<Texture *> *frames, int x, int y, int width, int height, bool rotated){ this->source = source; this->frames = frames; frame = -1; // Force an update of animated textures this->x = x; this->y = y; this->width = width; this->height = height; this->rotated = rotated;
float marginX = 0.0f; //0.01f / source->getWidth(); float marginY = 0.0f; //0.01f / source->getHeight();
this->u0 = x / (float) source->getWidth() + marginX; this->u1 = (x + width) / (float) source->getWidth() - marginX; this->v0 = y / (float) source->getHeight() + marginY; this->v1 = (y + height) / (float) source->getHeight() - marginY;
#ifndef _CONTENT_PACKAGE bool addBreakpoint = false; if(addBreakpoint) { printf("\nTreeTop\n"); printf("u0 = %f\n", u0); printf("u1 = %f\n", u1); printf("v0 = %f\n", v0); printf("v1 = %f\n", v1); printf("\n\n"); }#endif
this->widthTranslation = width / (float) SharedConstants::WORLD_RESOLUTION; this->heightTranslation = height / (float) SharedConstants::WORLD_RESOLUTION;}
void StitchedTexture::replaceWith(StitchedTexture *texture){ init(texture->source, texture->frames, texture->x, texture->y, texture->width, texture->height, texture->rotated);}
int StitchedTexture::getX() const{ return x;}
int StitchedTexture::getY() const{ return y;}
int StitchedTexture::getWidth() const{ return width;}
int StitchedTexture::getHeight() const{ return height;}
static const float UVAdjust = (1.0f/16.0f)/256.0f;
float StitchedTexture::getU0(bool adjust/*=false*/) const{ return adjust ? ( u0 + UVAdjust ) : u0;}
float StitchedTexture::getU1(bool adjust/*=false*/) const{ return adjust ? ( u1 - UVAdjust ) : u1;}
float StitchedTexture::getU(double offset, bool adjust/*=false*/) const{ float diff = getU1(adjust) - getU0(adjust); return getU0(adjust) + (diff * ((float) offset / SharedConstants::WORLD_RESOLUTION));}
float StitchedTexture::getV0(bool adjust/*=false*/) const{ return adjust ? ( v0 + UVAdjust ) : v0;}
float StitchedTexture::getV1(bool adjust/*=false*/) const{ return adjust ? ( v1 - UVAdjust ) : v1;}
float StitchedTexture::getV(double offset, bool adjust/*=false*/) const{ float diff = getV1(adjust) - getV0(adjust); return getV0(adjust) + (diff * ((float) offset / SharedConstants::WORLD_RESOLUTION));}
wstring StitchedTexture::getName() const{ return name;}
int StitchedTexture::getSourceWidth() const{ return source->getWidth();}
int StitchedTexture::getSourceHeight() const{ return source->getHeight();}
void StitchedTexture::cycleFrames(){ if (frameOverride != NULL) { pair<int, int> current = frameOverride->at(frame); subFrame++; if (subFrame >= current.second) { int oldFrame = current.first; frame = (frame + 1) % frameOverride->size(); subFrame = 0;
current = frameOverride->at(frame); int newFrame = current.first; if (oldFrame != newFrame && newFrame >= 0 && newFrame < frames->size()) { source->blit(x, y, frames->at(newFrame), rotated); } }
} else { int oldFrame = frame; frame = (frame + 1) % frames->size();
if (oldFrame != frame) { source->blit(x, y, frames->at(this->frame), rotated); } }}
Texture *StitchedTexture::getSource(){ return source;}
Texture *StitchedTexture::getFrame(int i){ return frames->at(0);}
int StitchedTexture::getFrames(){ return frames?frames->size():0;}
/*** Loads animation frames from a file with the syntax, <code>* 0,1,2,3,* 4*10,5*10,* 4*10,3,2,1,* 0* </code> or similar* * @param bufferedReader*/void StitchedTexture::loadAnimationFrames(BufferedReader *bufferedReader){ if(frameOverride != NULL) { delete frameOverride; frameOverride = NULL; } frame = 0; subFrame = 0;
intPairVector *results = new intPairVector();
//try { wstring line = bufferedReader->readLine(); while (!line.empty()) { line = trimString(line); if (line.length() > 0) { std::vector<std::wstring> tokens = stringSplit(line, L','); //for (String token : tokens) for(AUTO_VAR(it, tokens.begin()); it != tokens.end(); ++it) { wstring token = *it; int multiPos = token.find_first_of('*'); if (multiPos > 0) { int frame = _fromString<int>(token.substr(0, multiPos)); int count = _fromString<int>(token.substr(multiPos + 1)); results->push_back( intPairVector::value_type(frame, count)); } else { int tokenVal = _fromString<int>(token); results->push_back( intPairVector::value_type(tokenVal, 1)); } } } line = bufferedReader->readLine(); } //} catch (Exception e) { // System.err.println("Failed to read animation info for " + name + ": " + e.getMessage()); //}
if (!results->empty() && results->size() < (SharedConstants::TICKS_PER_SECOND * 30)) { frameOverride = results; } else { delete results; }}
void StitchedTexture::loadAnimationFrames(const wstring &string){ if(frameOverride != NULL) { delete frameOverride; frameOverride = NULL; } frame = 0; subFrame = 0;
intPairVector *results = new intPairVector();
std::vector<std::wstring> tokens = stringSplit(trimString(string), L','); //for (String token : tokens) for(AUTO_VAR(it, tokens.begin()); it != tokens.end(); ++it) { wstring token = trimString(*it); int multiPos = token.find_first_of('*'); if (multiPos > 0) { int frame = _fromString<int>(token.substr(0, multiPos)); int count = _fromString<int>(token.substr(multiPos + 1)); results->push_back( intPairVector::value_type(frame, count)); } else if(!token.empty()) { int tokenVal = _fromString<int>(token); results->push_back( intPairVector::value_type(tokenVal, 1)); } }
if (!results->empty() && results->size() < (SharedConstants::TICKS_PER_SECOND * 30)) { frameOverride = results; } else { delete results; }}
void StitchedTexture::setFlags(int flags){ this->flags = flags;}
int StitchedTexture::getFlags() const{ return this->flags;}
bool StitchedTexture::hasOwnData(){ return true;}