Школа такая поебота я не могу

This commit is contained in:
DepressedTWM 2026-05-15 12:40:57 +04:00
parent 9a074f8e82
commit 704c9b2f64
5 changed files with 59 additions and 110 deletions

View file

@ -15,8 +15,18 @@ set(CMAKE_INCLUDE_CURRENT_DIR ON)
# Debug stuff # Debug stuff
# i want die # i want die
if(DEBUG) if(DEBUG)
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -g3 -O0 -fno-omit-frame-pointer -ggdb") if (MSVC)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -g3 -O0 -fno-omit-frame-pointer -ggdb") add_compile_options(/W4 /dynamicdeopt /Od /fsanitize /GS /guard /validate-charset)
else()
add_compile_options(-g3 -O0 -fno-omit-frame-pointer -ggdb -Wall)
endif()
else()
# Optimization stuff
if (MSVC)
add_compile_options(/O2 /fp:fast /GA /GL /Gw Qpar /RTCu)
else()
add_compile_options(-0fast -ffast-math -fdevirtualize-speculatively -fspeculatively-call-stored-functions -fipa-pta -fdelete-null-pointer-checks -flimit-function-alignment)
endif()
endif() endif()
## Setup main source ## ## Setup main source ##

View file

@ -25,13 +25,9 @@
#include "glstate.h" #include "glstate.h"
#include "quad.h" #include "quad.h"
namespace GLMeta namespace GLMeta{
{
void subRectImageUpload(GLint srcW, GLint srcX, GLint srcY, void subRectImageUpload(GLint srcW, GLint srcX, GLint srcY, GLint dstX, GLint dstY, GLsizei dstW, GLsizei dstH, SDL_Surface *src, GLenum format){
GLint dstX, GLint dstY, GLsizei dstW, GLsizei dstH,
SDL_Surface *src, GLenum format)
{
if (gl.unpack_subimage){ if (gl.unpack_subimage){
gl.PixelStorei(GL_UNPACK_ROW_LENGTH, srcW); gl.PixelStorei(GL_UNPACK_ROW_LENGTH, srcW);
gl.PixelStorei(GL_UNPACK_SKIP_PIXELS, srcX); gl.PixelStorei(GL_UNPACK_SKIP_PIXELS, srcX);
@ -54,10 +50,8 @@ void subRectImageUpload(GLint srcW, GLint srcX, GLint srcY,
} }
} }
void subRectImageEnd() void subRectImageEnd(){
{ if (gl.unpack_subimage){
if (gl.unpack_subimage)
{
gl.PixelStorei(GL_UNPACK_ROW_LENGTH, 0); gl.PixelStorei(GL_UNPACK_ROW_LENGTH, 0);
gl.PixelStorei(GL_UNPACK_SKIP_PIXELS, 0); gl.PixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
gl.PixelStorei(GL_UNPACK_SKIP_ROWS, 0); gl.PixelStorei(GL_UNPACK_SKIP_ROWS, 0);
@ -66,13 +60,11 @@ void subRectImageEnd()
#define HAVE_NATIVE_VAO false //gl.GenVertexArrays #define HAVE_NATIVE_VAO false //gl.GenVertexArrays
static void vaoBindRes(VAO &vao) static void vaoBindRes(VAO &vao){
{
VBO::bind(vao.vbo); VBO::bind(vao.vbo);
IBO::bind(vao.ibo); IBO::bind(vao.ibo);
for (size_t i = 0; i < vao.attrCount; ++i) for (size_t i = 0; i < vao.attrCount; ++i){
{
const VertexAttribute &va = vao.attr[i]; const VertexAttribute &va = vao.attr[i];
gl.EnableVertexAttribArray(va.index); gl.EnableVertexAttribArray(va.index);
@ -80,48 +72,39 @@ static void vaoBindRes(VAO &vao)
} }
} }
void vaoInit(VAO &vao, bool keepBound) void vaoInit(VAO &vao, bool keepBound){
{ if (HAVE_NATIVE_VAO){
if (HAVE_NATIVE_VAO)
{
gl.GenVertexArrays(1, &vao.nativeVAO); gl.GenVertexArrays(1, &vao.nativeVAO);
gl.BindVertexArray(vao.nativeVAO); gl.BindVertexArray(vao.nativeVAO);
vaoBindRes(vao); vaoBindRes(vao);
if (!keepBound) if (!keepBound)
gl.BindVertexArray(0); gl.BindVertexArray(0);
} }
else else{
{ if (keepBound){
if (keepBound)
{
VBO::bind(vao.vbo); VBO::bind(vao.vbo);
IBO::bind(vao.ibo); IBO::bind(vao.ibo);
} }
} }
} }
void vaoFini(VAO &vao) void vaoFini(VAO &vao){
{
if (HAVE_NATIVE_VAO) if (HAVE_NATIVE_VAO)
gl.DeleteVertexArrays(1, &vao.nativeVAO); gl.DeleteVertexArrays(1, &vao.nativeVAO);
} }
void vaoBind(VAO &vao) void vaoBind(VAO &vao){
{
if (HAVE_NATIVE_VAO) if (HAVE_NATIVE_VAO)
gl.BindVertexArray(vao.nativeVAO); gl.BindVertexArray(vao.nativeVAO);
else else
vaoBindRes(vao); vaoBindRes(vao);
} }
void vaoUnbind(VAO &vao) void vaoUnbind(VAO &vao){
{ if (HAVE_NATIVE_VAO){
if (HAVE_NATIVE_VAO)
{
gl.BindVertexArray(0); gl.BindVertexArray(0);
} }
else else{
{
for (size_t i = 0; i < vao.attrCount; ++i) for (size_t i = 0; i < vao.attrCount; ++i)
gl.DisableVertexAttribArray(vao.attr[i].index); gl.DisableVertexAttribArray(vao.attr[i].index);
@ -132,14 +115,11 @@ void vaoUnbind(VAO &vao)
#define HAVE_NATIVE_BLIT false //gl.BlitFramebuffer #define HAVE_NATIVE_BLIT false //gl.BlitFramebuffer
static void _blitBegin(FBO::ID fbo, const Vec2i &size) static void _blitBegin(FBO::ID fbo, const Vec2i &size){
{ if (HAVE_NATIVE_BLIT){
if (HAVE_NATIVE_BLIT)
{
gl.BindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo.gl); gl.BindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo.gl);
} }
else else{
{
FBO::bind(fbo); FBO::bind(fbo);
glState.viewport.pushSet(IntRect(0, 0, size.x, size.y)); glState.viewport.pushSet(IntRect(0, 0, size.x, size.y));
@ -150,45 +130,36 @@ static void _blitBegin(FBO::ID fbo, const Vec2i &size)
} }
} }
void blitBegin(TEXFBO &target) void blitBegin(TEXFBO &target){
{
_blitBegin(target.fbo, Vec2i(target.width, target.height)); _blitBegin(target.fbo, Vec2i(target.width, target.height));
} }
void blitBeginScreen(const Vec2i &size) void blitBeginScreen(const Vec2i &size){
{
_blitBegin(FBO::ID(0), size); _blitBegin(FBO::ID(0), size);
} }
void blitSource(TEXFBO &source) void blitSource(TEXFBO &source){
{ if (HAVE_NATIVE_BLIT){
if (HAVE_NATIVE_BLIT)
{
gl.BindFramebuffer(GL_READ_FRAMEBUFFER, source.fbo.gl); gl.BindFramebuffer(GL_READ_FRAMEBUFFER, source.fbo.gl);
} }
else else{
{
SimpleShader &shader = shState->shaders().simple; SimpleShader &shader = shState->shaders().simple;
shader.setTexSize(Vec2i(source.width, source.height)); shader.setTexSize(Vec2i(source.width, source.height));
TEX::bind(source.tex); TEX::bind(source.tex);
} }
} }
void blitRectangle(const IntRect &src, const Vec2i &dstPos) void blitRectangle(const IntRect &src, const Vec2i &dstPos){
{
blitRectangle(src, IntRect(dstPos.x, dstPos.y, src.w, src.h), false); blitRectangle(src, IntRect(dstPos.x, dstPos.y, src.w, src.h), false);
} }
void blitRectangle(const IntRect &src, const IntRect &dst, bool smooth) void blitRectangle(const IntRect &src, const IntRect &dst, bool smooth){
{ if (HAVE_NATIVE_BLIT){
if (HAVE_NATIVE_BLIT)
{
gl.BlitFramebuffer(src.x, src.y, src.x+src.w, src.y+src.h, gl.BlitFramebuffer(src.x, src.y, src.x+src.w, src.y+src.h,
dst.x, dst.y, dst.x+dst.w, dst.y+dst.h, dst.x, dst.y, dst.x+dst.w, dst.y+dst.h,
GL_COLOR_BUFFER_BIT, smooth ? GL_LINEAR : GL_NEAREST); GL_COLOR_BUFFER_BIT, smooth ? GL_LINEAR : GL_NEAREST);
} }
else else{
{
if (smooth) if (smooth)
TEX::setSmooth(true); TEX::setSmooth(true);
@ -203,8 +174,7 @@ void blitRectangle(const IntRect &src, const IntRect &dst, bool smooth)
} }
} }
void blitEnd() void blitEnd(){
{
if (!HAVE_NATIVE_BLIT) if (!HAVE_NATIVE_BLIT)
glState.viewport.pop(); glState.viewport.pop();
} }

View file

@ -258,8 +258,7 @@ public:
screenQuad.draw(); screenQuad.draw();
} }
if (flashEffect) if (flashEffect){
{
shader.setColor(f); shader.setColor(f);
screenQuad.draw(); screenQuad.draw();
} }
@ -373,8 +372,7 @@ struct FPSLimiter{
* relative to the ideal timestep */ * relative to the ideal timestep */
adj.idealDiff = diff - tpf + adj.idealDiff; adj.idealDiff = diff - tpf + adj.idealDiff;
if (adj.resetFlag) if (adj.resetFlag){
{
adj.idealDiff = 0; adj.idealDiff = 0;
adj.resetFlag = false; adj.resetFlag = false;
} }
@ -388,8 +386,7 @@ struct FPSLimiter{
* of ticks behind the ideal timestep, * of ticks behind the ideal timestep,
* there's no choice but to skip frame(s) * there's no choice but to skip frame(s)
* to catch up */ * to catch up */
bool frameSkipRequired() const bool frameSkipRequired() const{
{
if (disabled) if (disabled)
return false; return false;
@ -405,15 +402,14 @@ private:
req.tv_nsec = nsec % NS_PER_S; req.tv_nsec = nsec % NS_PER_S;
errno = 0; errno = 0;
while (nanosleep(&req, &req) == -1) while (nanosleep(&req, &req) == -1){
{
int err = errno; int err = errno;
errno = 0; errno = 0;
if (err == EINTR) if (err == EINTR)
continue; continue;
Debug() << "nanosleep failed. errno:" << err; Debug() << "[delayTicks] nanosleep failed. errno:" << err;
SDL_Delay(ticks / tickFreqMS); SDL_Delay(ticks / tickFreqMS);
break; break;
} }
@ -577,8 +573,7 @@ struct GraphicsPrivate{
} }
void redrawScreen(){ void redrawScreen(){
if (shState->oneshot().obscuredDirty) if (shState->oneshot().obscuredDirty){
{
TEX::bind(obscuredTex); TEX::bind(obscuredTex);
TEX::uploadSubImage(0, 0, 640, 480, shState->oneshot().obscuredMap().data(), GL_LUMINANCE); TEX::uploadSubImage(0, 0, 640, 480, shState->oneshot().obscuredMap().data(), GL_LUMINANCE);
shState->oneshot().obscuredDirty = false; shState->oneshot().obscuredDirty = false;
@ -638,19 +633,15 @@ void Graphics::update(bool limitFps){
return; return;
if (limitFps){ if (limitFps){
if (p->fpsLimiter.frameSkipRequired()) if (p->fpsLimiter.frameSkipRequired()){
{ if (p->threadData->config.frameSkip){
if (p->threadData->config.frameSkip)
{
/* Skip frame */ /* Skip frame */
p->fpsLimiter.delay(); p->fpsLimiter.delay();
++p->frameCount; ++p->frameCount;
p->threadData->ethread->notifyFrame(); p->threadData->ethread->notifyFrame();
return; return;
} }else{
else
{
/* Just reset frame adjust counter */ /* Just reset frame adjust counter */
p->fpsLimiter.resetFrameAdjust(); p->fpsLimiter.resetFrameAdjust();
} }
@ -676,10 +667,7 @@ void Graphics::freeze(){
p->compositeToBuffer(p->frozenScene); p->compositeToBuffer(p->frozenScene);
} }
void Graphics::transition(int duration, void Graphics::transition(int duration, const char *filename, int vague){
const char *filename,
int vague)
{
p->checkSyncLock(); p->checkSyncLock();
if (!p->frozen) if (!p->frozen)
@ -824,8 +812,7 @@ void Graphics::fadeout(int duration){
for (int i = duration-1; i > -1; --i){ for (int i = duration-1; i > -1; --i){
setBrightness(diff + (curr / duration) * i); setBrightness(diff + (curr / duration) * i);
if (p->frozen) if (p->frozen){
{
GLMeta::blitBeginScreen(p->scSize); GLMeta::blitBeginScreen(p->scSize);
GLMeta::blitSource(p->frozenScene); GLMeta::blitSource(p->frozenScene);
@ -836,8 +823,7 @@ void Graphics::fadeout(int duration){
p->swapGLBuffer(); p->swapGLBuffer();
} }
else else{
{
update(); update();
} }
} }
@ -852,8 +838,7 @@ void Graphics::fadein(int duration){
for (int i = 1; i <= duration; ++i){ for (int i = 1; i <= duration; ++i){
setBrightness(curr + (diff / duration) * i); setBrightness(curr + (diff / duration) * i);
if (p->frozen) if (p->frozen){
{
GLMeta::blitBeginScreen(p->scSize); GLMeta::blitBeginScreen(p->scSize);
GLMeta::blitSource(p->frozenScene); GLMeta::blitSource(p->frozenScene);
@ -864,8 +849,7 @@ void Graphics::fadein(int duration){
p->swapGLBuffer(); p->swapGLBuffer();
} }
else else{
{
update(); update();
} }
} }
@ -912,7 +896,7 @@ void Graphics::resizeScreen(int width, int height){
} }
void Graphics::playMovie(const char *filename){ void Graphics::playMovie(const char *filename){
Debug() << "Graphics.playMovie(" << filename << ") not implemented"; Debug() << "[playMovie] Graphics.playMovie(" << filename << ") not implemented";
} }
DEF_ATTR_RD_SIMPLE(Graphics, Brightness, int, p->brightness) DEF_ATTR_RD_SIMPLE(Graphics, Brightness, int, p->brightness)
@ -1022,3 +1006,4 @@ void Graphics::remDisposable(Disposable *d){
const TEX::ID &Graphics::obscuredTex() const{ const TEX::ID &Graphics::obscuredTex() const{
return p->obscuredTex; return p->obscuredTex;
} }

View file

@ -280,19 +280,8 @@ int main(int argc, char *argv[]){
if (conf.windowTitle.empty()) if (conf.windowTitle.empty())
conf.windowTitle = conf.game.title; conf.windowTitle = conf.game.title;
//IMG_Init() and IMG_Quit() are no longer necessary. If an image format requires dynamically loading a support library, that will be done automatically.
//int imgFlags = IMG_INIT_PNG;
//if (IMG_Init(imgFlags) != imgFlags)
//{
// showInitError(std::string("Error initializing SDL_image: ") + SDL_GetError());
// SDL_Quit();
//
// return 0;
//}
if (TTF_Init() < 0){ if (TTF_Init() < 0){
showInitError(std::string("Error initializing SDL_ttf: ") + SDL_GetError()); showInitError(std::string("Error initializing SDL_ttf: ") + SDL_GetError());
//IMG_Quit();
SDL_Quit(); SDL_Quit();
return 0; return 0;
@ -301,25 +290,23 @@ int main(int argc, char *argv[]){
if (Sound_Init() == 0){ if (Sound_Init() == 0){
showInitError(std::string("Error initializing SDL_sound: ") + Sound_GetError()); showInitError(std::string("Error initializing SDL_sound: ") + Sound_GetError());
TTF_Quit(); TTF_Quit();
//IMG_Quit();
SDL_Quit(); SDL_Quit();
return 0; return 0;
} }
SDL_Window *win; SDL_Window *win;
Uint32 winFlags = SDL_WINDOW_OPENGL | SDL_WINDOW_INPUT_FOCUS; //| SDL_WINDOW_ALLOW_HIGHDPI; Uint32 winFlags = SDL_WINDOW_OPENGL | SDL_WINDOW_INPUT_FOCUS;
// #ifdef __APPLE__ // #ifdef __APPLE__
// winFlags |= SDL_WINDOW_RESIZABLE; // winFlags |= SDL_WINDOW_RESIZABLE;
// #endif // #endif
//SDL_CreateWindow() has been simplified and no longer takes a window position.
win = SDL_CreateWindow(conf.windowTitle.c_str(), conf.defScreenW, conf.defScreenH, winFlags); win = SDL_CreateWindow(conf.windowTitle.c_str(), conf.defScreenW, conf.defScreenH, winFlags);
if (conf.fullscreen) if (conf.fullscreen)
SDL_SetWindowFullscreen(win, true); SDL_SetWindowFullscreen(win, true);
if (!win){ if (!win){
showInitError(std::string("Error creating window: ") + SDL_GetError()); showInitError(std::string("Error creating window: ") + SDL_GetError());
return 0; return 0;
@ -415,8 +402,6 @@ int main(int argc, char *argv[]){
Sound_Quit(); Sound_Quit();
TTF_Quit(); TTF_Quit();
//IMG_Init() and IMG_Quit() are no longer necessary. If an image format requires dynamically loading a support library, that will be done automatically.
//IMG_Quit();
SDL_Quit(); SDL_Quit();
#ifdef STEAM #ifdef STEAM

View file

@ -52,8 +52,7 @@
#include <math.h> #include <math.h>
#include <string.h> #include <string.h>
class Transform class Transform{
{
public: public:
Transform() Transform()
: scale(1, 1), : scale(1, 1),