Полировка движка

This commit is contained in:
DepressedTWM 2026-05-28 18:19:24 +04:00
parent e4de91bde2
commit 749e97eebd
13 changed files with 35 additions and 66 deletions

View file

@ -47,9 +47,9 @@
#define GUARD_MEGA \
{ \
if (p->megaSurface) { \
crash("Operation not supported for mega surfaces", Exception::MKXPError, true); \
} \
if (p->megaSurface) \
throw Exception(Exception::MKXPError, \
"Operation not supported for mega surfaces"); \
}
#define OUTLINE_SIZE 1
@ -229,7 +229,7 @@ Bitmap::Bitmap(const char *filename){
if (!imgSurf){
snprintf(msg, sizeof msg, "Error loading image '%s': %s", filename, SDL_GetError());
crash(msg, Exception::SDLError, true);
throw Exception(Exception::SDLError, msg);
}
p->ensureFormat(imgSurf, SDL_PIXELFORMAT_ABGR8888);
@ -265,7 +265,8 @@ Bitmap::Bitmap(const char *filename){
Bitmap::Bitmap(int width, int height){
if (width <= 0 || height <= 0){
crash("failed to create bitmap", Exception::RGSSError, true);
//rash("failed to create bitmap");
throw Exception(Exception::RGSSError, "failed to create bitmap");
}
TEXFBO tex = shState->texPool().request(width, height);
@ -410,7 +411,8 @@ void Bitmap::stretchBlt(const IntRect &destRect, const Bitmap &source, const Int
}
else{
/* Clipped blit */
GLMeta::subRectImageUpload(blitTemp->w, bltRect.x - dstRect.x, bltRect.y - dstRect.y, bltRect.x, bltRect.y, bltRect.w, bltRect.h, blitTemp, GL_RGBA);
GLMeta::subRectImageUpload(blitTemp->w, bltRect.x - dstRect.x, bltRect.y - dstRect.y,
bltRect.x, bltRect.y, bltRect.w, bltRect.h, blitTemp, GL_RGBA);
GLMeta::subRectImageEnd();
}

View file

@ -54,7 +54,7 @@ struct SDLRWIoContext{
filename(filename)
{
if (!ops)
crash("Failed to open file", Exception::SDLError, true);
throw Exception(Exception::SDLError, "Failed to open file: %s", SDL_GetError());
}
~SDLRWIoContext(){
@ -69,6 +69,7 @@ static SDL_IOStream *getSDLRWops(PHYSFS_Io *io){
}
static PHYSFS_sint64 SDLRWIoRead(struct PHYSFS_Io *io, void *buf, PHYSFS_uint64 len){
// return SDL_ReadIO(getSDLRWops(io), buf, 1, len);
return SDL_ReadIO(getSDLRWops(io), buf, len);
}
@ -118,7 +119,6 @@ static PHYSFS_Io *createSDLRWIo(const char *filename){
try{
ctx = new SDLRWIoContext(filename);
}catch (const Exception &e){
Debug() << "Failed mounting" << filename;
return 0;
}
@ -562,7 +562,6 @@ openReadEnumCB(void *d, const char *dirpath, const char *filename){
void FileSystem::openRead(OpenHandler &handler, const char *filename){
char buffer[512];
char msg[512];
size_t len = strcpySafe(buffer, filename, sizeof(buffer), -1);
char *delim;
@ -588,7 +587,8 @@ void FileSystem::openRead(OpenHandler &handler, const char *filename){
dir = buffer;
}
OpenReadEnumData data(handler, file, len + buffer - delim - !root, p->havePathCache ? &p->pathCache : 0);
OpenReadEnumData data(handler, file, len + buffer - delim - !root,
p->havePathCache ? &p->pathCache : 0);
if (p->havePathCache){
/* Get the list of files contained in this directory
@ -601,22 +601,17 @@ void FileSystem::openRead(OpenHandler &handler, const char *filename){
PHYSFS_enumerate(dir, openReadEnumCB, &data);
}
if (data.physfsError){
snprintf(msg, sizeof msg, "PhysFS: %s", data.physfsError);
crash(msg, Exception::PHYSFSError, true);
}
if (data.physfsError)
throw Exception(Exception::PHYSFSError, "PhysFS: %s", data.physfsError);
if (data.matchCount == 0){
snprintf(msg, sizeof msg, "NoFileError: %s", data.physfsError);
crash(msg, Exception::NoFileError, true);
}
if (data.matchCount == 0)
throw Exception(Exception::NoFileError, "%s", filename);
}
void FileSystem::openReadRaw(SDL_IOStream* &stream, const char *filename){
PHYSFS_File *handle = PHYSFS_openRead(filename);
if (!handle){
if (!handle)
throw Exception(Exception::NoFileError, "%s", filename);
}
initReadOps(handle, stream);
}

View file

@ -564,9 +564,7 @@ struct GraphicsPrivate{
}
void metaBlitBufferFlippedScaled(){
GLMeta::blitRectangle(IntRect(0, 0, scRes.x, scRes.y),
IntRect(scOffset.x, scSize.y+scOffset.y, scSize.x, -scSize.y),
threadData->config.smoothScaling);
GLMeta::blitRectangle(IntRect(0, 0, scRes.x, scRes.y), IntRect(scOffset.x, scSize.y+scOffset.y, scSize.x, -scSize.y), threadData->config.smoothScaling);
}
void redrawScreen(){

View file

@ -160,10 +160,6 @@ int rgssThreadFun(void *userdata){
return 0;
}
static void showInitError(const std::string &msg){
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error :(", msg.c_str(), 0);
}
static void setupWindowIcon(const Config &conf, SDL_Window *win){
SDL_IOStream *iconSrc;
@ -241,13 +237,13 @@ int main(int argc, char *argv[]){
#ifdef STEAM
if (!STEAMSHIM_init()){
crash("Could not initialize Steamworks API", Exception::MEOW, true);
return 0
crash("Could not initialize Steamworks API", Exception::MEOW, false);
return 0;
}
#endif
if (!EventThread::allocUserEvents()){
crash("Error allocating SDL user events", Exception::MEOW, true);
crash("Error allocating SDL user events", Exception::MEOW, false);
return 0;
}
@ -281,7 +277,7 @@ int main(int argc, char *argv[]){
if (!conf.gameFolder.empty()){
if (chdir(conf.gameFolder.c_str()) != 0){
snprintf(msg, sizeof msg, "Unable to switch into gameFolder %s", conf.gameFolder);
crash(msg, Exception::MEOW, true);
crash(msg, Exception::MEOW, false);
return 0;
}
}
@ -337,7 +333,7 @@ int main(int argc, char *argv[]){
if (!alcDev){
SDL_DestroyWindow(win);
crash("Error opening OpenAL device", Exception::MEOW, true);
crash("Error opening OpenAL device", Exception::MEOW, false);
TTF_Quit();
SDL_Quit();
@ -391,7 +387,7 @@ int main(int argc, char *argv[]){
if (rtData.rqTermAck)
SDL_WaitThread(rgssThread, 0);
else
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, conf.windowTitle.c_str(), "The RGSS script seems to be stuck and OneShot: Sunshine will now force quit", win);
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, conf.windowTitle.c_str(), "The RGSS script seems to be stuck and Sunshine will now force quit", win);
if (!rtData.rgssErrorMsg.empty())
crash(rtData.rgssErrorMsg.c_str(), Exception::MEOW, false);

View file

@ -11,10 +11,6 @@
#include "pipe.h"
#include "meow.h"
static void showInitError(const std::string &msg){
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Sunshine Error", msg.c_str(), 0);
}
static bool readMessage(Pipe &ipc, char *buf, size_t size){
size_t index = 0;
while (index < size - 1) {

View file

@ -970,8 +970,7 @@ SettingsMenu::SettingsMenu(RGSSThreadData &rtData){
p->hasFocus = false;
p->destroyReq = false;
p->window = SDL_CreateWindow(findtext(TRSTR_KEYBIND_TITLE, "Key bindings"),
winSize.x, winSize.y, SDL_WINDOW_INPUT_FOCUS);
p->window = SDL_CreateWindow(findtext(TRSTR_KEYBIND_TITLE, "Key bindings"), winSize.x, winSize.y, SDL_WINDOW_INPUT_FOCUS);
p->winSurf = SDL_GetWindowSurface(p->window);
p->winID = SDL_GetWindowID(p->window);
@ -1045,9 +1044,7 @@ SettingsMenu::~SettingsMenu() {
delete p;
}
bool SettingsMenu::onEvent(const SDL_Event &event,
const std::map<int, SDL_Joystick*> &joysticks)
{
bool SettingsMenu::onEvent(const SDL_Event &event, const std::map<int, SDL_Joystick*> &joysticks) {
switch (event.window.type) {
case SDL_EVENT_WINDOW_SHOWN : // SDL is bugged and doesn't give us a first FOCUS_GAINED event
case SDL_EVENT_WINDOW_FOCUS_GAINED :

View file

@ -41,12 +41,8 @@ protected:
Shader();
~Shader();
void init(const unsigned char *vert, int vertSize,
const unsigned char *frag, int fragSize,
const char *vertName, const char *fragName,
const char *programName);
void initFromFile(const char *vertFile, const char *fragFile,
const char *programName);
void init(const unsigned char *vert, int vertSize, const unsigned char *frag, int fragSize, const char *vertName, const char *fragName, const char *programName);
void initFromFile(const char *vertFile, const char *fragFile, const char *programName);
static void setVec4Uniform(GLint location, const Vec4 &vec);
static void setTexUniform(GLint location, unsigned unitIndex, TEX::ID texture);

View file

@ -73,8 +73,7 @@ private:
};
/* Before: [a][b][c][d], After (index=1): [a][c][d][b] */
static void
arrayPushBack(std::vector<size_t> &array, size_t size, size_t index){
static void arrayPushBack(std::vector<size_t> &array, size_t size, size_t index){
size_t v = array[index];
for (size_t t = index; t < size-1; ++t)
@ -227,8 +226,6 @@ SoundBuffer *SoundEmitter::allocateBuffer(const std::string &filename){
char buf[512];
snprintf(buf, sizeof(buf), "Unable to decode sound: %s: %s", filename.c_str(), Sound_GetError());
crash(msg, Exception::MEOW, false);
Debug() << buf;
return 0;
}

View file

@ -51,9 +51,7 @@ struct SoundEmitter{
SoundEmitter(const Config &conf);
~SoundEmitter();
void play(const std::string &filename,
int volume,
int pitch);
void play(const std::string &filename, int volume, int pitch);
void stop();

View file

@ -141,8 +141,7 @@ static BlitVec calcBlitsInt(ColumnVec &srcCols, ColumnVec &dstCols){
}
else{
/* srcCol fits perfectly into dstCol */
blits.push_back(Blit(srcCol.x, srcCol.y,
dstCol.x, dstCol.y, dstCol.h));
blits.push_back(Blit(srcCol.x, srcCol.y, dstCol.x, dstCol.y, dstCol.h));
}
}
}

View file

@ -69,8 +69,7 @@ enum AtSubPos{
BottomRightTable = 5
};
static inline void
atSelectSubPos(FloatRect &pos, int i){
static inline void atSelectSubPos(FloatRect &pos, int i){
switch (i){
case TopLeft:
return;

View file

@ -38,7 +38,6 @@
#include "vertex.h"
#include "tileatlas.h"
#include "tilemap-common.h"
#include "meow.h"
#include <sigc++/connection.h>
@ -401,7 +400,7 @@ struct TilemapPrivate {
atlas.size = TileAtlas::minSize(atlas.efTilesetH, glState.caps.maxTexSize);
if (atlas.size.x < 0)
crash("Cannot allocate big enough texture for tileset atlas", Exception::MKXPError, true);
throw Exception(Exception::MKXPError, "Cannot allocate big enough texture for tileset atlas");
}
void updateAutotileInfo(){
@ -1168,4 +1167,3 @@ void Tilemap::releaseResources(){
delete p;
atProxy.p = 0;
}

View file

@ -54,11 +54,9 @@ namespace TileQuads{
Vertex *verts);
/* Build a quad "frame" (see Window cursor_rect) */
int buildFrame(const IntRect &rect,
Vertex vert[36]);
int buildFrame(const IntRect &rect, Vertex vert[36]);
int buildFrameSource(const IntRect &rect,
Vertex vert[36]);
int buildFrameSource(const IntRect &rect, Vertex vert[36]);
}
#endif // TILEQUAD_H