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

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 \ #define GUARD_MEGA \
{ \ { \
if (p->megaSurface) { \ if (p->megaSurface) \
crash("Operation not supported for mega surfaces", Exception::MKXPError, true); \ throw Exception(Exception::MKXPError, \
} \ "Operation not supported for mega surfaces"); \
} }
#define OUTLINE_SIZE 1 #define OUTLINE_SIZE 1
@ -229,7 +229,7 @@ Bitmap::Bitmap(const char *filename){
if (!imgSurf){ if (!imgSurf){
snprintf(msg, sizeof msg, "Error loading image '%s': %s", filename, SDL_GetError()); 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); p->ensureFormat(imgSurf, SDL_PIXELFORMAT_ABGR8888);
@ -265,7 +265,8 @@ Bitmap::Bitmap(const char *filename){
Bitmap::Bitmap(int width, int height){ Bitmap::Bitmap(int width, int height){
if (width <= 0 || height <= 0){ 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); TEXFBO tex = shState->texPool().request(width, height);
@ -410,7 +411,8 @@ void Bitmap::stretchBlt(const IntRect &destRect, const Bitmap &source, const Int
} }
else{ else{
/* Clipped blit */ /* 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(); GLMeta::subRectImageEnd();
} }

View file

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

View file

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

View file

@ -160,10 +160,6 @@ int rgssThreadFun(void *userdata){
return 0; 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){ static void setupWindowIcon(const Config &conf, SDL_Window *win){
SDL_IOStream *iconSrc; SDL_IOStream *iconSrc;
@ -241,13 +237,13 @@ int main(int argc, char *argv[]){
#ifdef STEAM #ifdef STEAM
if (!STEAMSHIM_init()){ if (!STEAMSHIM_init()){
crash("Could not initialize Steamworks API", Exception::MEOW, true); crash("Could not initialize Steamworks API", Exception::MEOW, false);
return 0 return 0;
} }
#endif #endif
if (!EventThread::allocUserEvents()){ if (!EventThread::allocUserEvents()){
crash("Error allocating SDL user events", Exception::MEOW, true); crash("Error allocating SDL user events", Exception::MEOW, false);
return 0; return 0;
} }
@ -281,7 +277,7 @@ int main(int argc, char *argv[]){
if (!conf.gameFolder.empty()){ if (!conf.gameFolder.empty()){
if (chdir(conf.gameFolder.c_str()) != 0){ if (chdir(conf.gameFolder.c_str()) != 0){
snprintf(msg, sizeof msg, "Unable to switch into gameFolder %s", conf.gameFolder); snprintf(msg, sizeof msg, "Unable to switch into gameFolder %s", conf.gameFolder);
crash(msg, Exception::MEOW, true); crash(msg, Exception::MEOW, false);
return 0; return 0;
} }
} }
@ -337,7 +333,7 @@ int main(int argc, char *argv[]){
if (!alcDev){ if (!alcDev){
SDL_DestroyWindow(win); SDL_DestroyWindow(win);
crash("Error opening OpenAL device", Exception::MEOW, true); crash("Error opening OpenAL device", Exception::MEOW, false);
TTF_Quit(); TTF_Quit();
SDL_Quit(); SDL_Quit();
@ -391,7 +387,7 @@ int main(int argc, char *argv[]){
if (rtData.rqTermAck) if (rtData.rqTermAck)
SDL_WaitThread(rgssThread, 0); SDL_WaitThread(rgssThread, 0);
else 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()) if (!rtData.rgssErrorMsg.empty())
crash(rtData.rgssErrorMsg.c_str(), Exception::MEOW, false); crash(rtData.rgssErrorMsg.c_str(), Exception::MEOW, false);

View file

@ -11,10 +11,6 @@
#include "pipe.h" #include "pipe.h"
#include "meow.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){ static bool readMessage(Pipe &ipc, char *buf, size_t size){
size_t index = 0; size_t index = 0;
while (index < size - 1) { while (index < size - 1) {

View file

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

View file

@ -41,12 +41,8 @@ protected:
Shader(); Shader();
~Shader(); ~Shader();
void init(const unsigned char *vert, int vertSize, void init(const unsigned char *vert, int vertSize, const unsigned char *frag, int fragSize, const char *vertName, const char *fragName, const char *programName);
const unsigned char *frag, int fragSize, void initFromFile(const char *vertFile, const char *fragFile, const char *programName);
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 setVec4Uniform(GLint location, const Vec4 &vec);
static void setTexUniform(GLint location, unsigned unitIndex, TEX::ID texture); 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] */ /* Before: [a][b][c][d], After (index=1): [a][c][d][b] */
static void static void arrayPushBack(std::vector<size_t> &array, size_t size, size_t index){
arrayPushBack(std::vector<size_t> &array, size_t size, size_t index){
size_t v = array[index]; size_t v = array[index];
for (size_t t = index; t < size-1; ++t) for (size_t t = index; t < size-1; ++t)
@ -227,8 +226,6 @@ SoundBuffer *SoundEmitter::allocateBuffer(const std::string &filename){
char buf[512]; char buf[512];
snprintf(buf, sizeof(buf), "Unable to decode sound: %s: %s", filename.c_str(), Sound_GetError()); snprintf(buf, sizeof(buf), "Unable to decode sound: %s: %s", filename.c_str(), Sound_GetError());
crash(msg, Exception::MEOW, false); crash(msg, Exception::MEOW, false);
Debug() << buf;
return 0; return 0;
} }

View file

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

View file

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

View file

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

View file

@ -38,7 +38,6 @@
#include "vertex.h" #include "vertex.h"
#include "tileatlas.h" #include "tileatlas.h"
#include "tilemap-common.h" #include "tilemap-common.h"
#include "meow.h"
#include <sigc++/connection.h> #include <sigc++/connection.h>
@ -401,7 +400,7 @@ struct TilemapPrivate {
atlas.size = TileAtlas::minSize(atlas.efTilesetH, glState.caps.maxTexSize); atlas.size = TileAtlas::minSize(atlas.efTilesetH, glState.caps.maxTexSize);
if (atlas.size.x < 0) 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(){ void updateAutotileInfo(){
@ -1168,4 +1167,3 @@ void Tilemap::releaseResources(){
delete p; delete p;
atProxy.p = 0; atProxy.p = 0;
} }

View file

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