Port to SDL2
FossilOrigin-Name: 42d4b57828b48b9e38d8be3edcebca4c7cbca9948d8792a320df1f92c13465be
This commit is contained in:
parent
c3cd8d4fac
commit
3a1bbe3110
7 changed files with 52 additions and 84 deletions
|
@ -9,12 +9,9 @@ add_global_arguments(
|
||||||
language: 'objcpp')
|
language: 'objcpp')
|
||||||
|
|
||||||
objfw_dep = dependency('objfw')
|
objfw_dep = dependency('objfw')
|
||||||
sdl_dep = dependency('sdl12_compat', required: false)
|
sdl_dep = dependency('SDL2')
|
||||||
if not sdl_dep.found()
|
sdlimage_dep = dependency('SDL2_image')
|
||||||
sdl_dep = dependency('SDL')
|
sdlmixer_dep = dependency('SDL2_mixer')
|
||||||
endif
|
|
||||||
sdlimage_dep = dependency('SDL_image')
|
|
||||||
sdlmixer_dep = dependency('SDL_mixer')
|
|
||||||
zlib_dep = dependency('zlib')
|
zlib_dep = dependency('zlib')
|
||||||
|
|
||||||
client_link_args = []
|
client_link_args = []
|
||||||
|
|
28
src/Cube.mm
28
src/Cube.mm
|
@ -54,6 +54,7 @@ alloc(int s) // for some big chunks... most other allocs use the memory pool
|
||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SDL_Window *window;
|
||||||
int scr_w = 640;
|
int scr_w = 640;
|
||||||
int scr_h = 480;
|
int scr_h = 480;
|
||||||
|
|
||||||
|
@ -90,12 +91,7 @@ screenshot()
|
||||||
COMMAND(screenshot, ARG_NONE)
|
COMMAND(screenshot, ARG_NONE)
|
||||||
COMMAND(quit, ARG_NONE)
|
COMMAND(quit, ARG_NONE)
|
||||||
|
|
||||||
void
|
bool keyrepeat = false;
|
||||||
keyrepeat(bool on)
|
|
||||||
{
|
|
||||||
SDL_EnableKeyRepeat(
|
|
||||||
on ? SDL_DEFAULT_REPEAT_DELAY : 0, SDL_DEFAULT_REPEAT_INTERVAL);
|
|
||||||
}
|
|
||||||
|
|
||||||
VARF(gamespeed, 10, 100, 1000, if (multiplayer()) gamespeed = 100);
|
VARF(gamespeed, 10, 100, 1000, if (multiplayer()) gamespeed = 100);
|
||||||
VARP(minmillis, 0, 5, 1000);
|
VARP(minmillis, 0, 5, 1000);
|
||||||
|
@ -176,14 +172,17 @@ int framesinmap = 0;
|
||||||
|
|
||||||
log("video: mode");
|
log("video: mode");
|
||||||
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
|
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
|
||||||
if (SDL_SetVideoMode(scr_w, scr_h, 0,
|
if ((window = SDL_CreateWindow("cube engine", SDL_WINDOWPOS_UNDEFINED,
|
||||||
SDL_OPENGL | (!windowed ? SDL_FULLSCREEN : 0)) == NULL)
|
SDL_WINDOWPOS_UNDEFINED, scr_w, scr_h,
|
||||||
|
SDL_WINDOW_SHOWN | SDL_WINDOW_OPENGL |
|
||||||
|
(!windowed ? SDL_WINDOW_FULLSCREEN : 0))) == NULL ||
|
||||||
|
SDL_GL_CreateContext(window) == NULL)
|
||||||
fatal(@"Unable to create OpenGL screen");
|
fatal(@"Unable to create OpenGL screen");
|
||||||
|
|
||||||
log("video: misc");
|
log("video: misc");
|
||||||
SDL_WM_SetCaption("cube engine", NULL);
|
SDL_SetWindowGrab(window, SDL_TRUE);
|
||||||
SDL_WM_GrabInput(SDL_GRAB_ON);
|
SDL_SetRelativeMouseMode(SDL_TRUE);
|
||||||
keyrepeat(false);
|
keyrepeat = false;
|
||||||
SDL_ShowCursor(0);
|
SDL_ShowCursor(0);
|
||||||
|
|
||||||
log("gl");
|
log("gl");
|
||||||
|
@ -241,7 +240,7 @@ int framesinmap = 0;
|
||||||
fps = (1000.0f / curtime + fps * 50) / 51;
|
fps = (1000.0f / curtime + fps * 50) / 51;
|
||||||
computeraytable(player1->o.x, player1->o.y);
|
computeraytable(player1->o.x, player1->o.y);
|
||||||
readdepth(scr_w, scr_h);
|
readdepth(scr_w, scr_h);
|
||||||
SDL_GL_SwapBuffers();
|
SDL_GL_SwapWindow(window);
|
||||||
extern void updatevol();
|
extern void updatevol();
|
||||||
updatevol();
|
updatevol();
|
||||||
if (framesinmap++ <
|
if (framesinmap++ <
|
||||||
|
@ -263,16 +262,17 @@ int framesinmap = 0;
|
||||||
|
|
||||||
case SDL_KEYDOWN:
|
case SDL_KEYDOWN:
|
||||||
case SDL_KEYUP:
|
case SDL_KEYUP:
|
||||||
|
if (keyrepeat || event.key.repeat == 0)
|
||||||
keypress(event.key.keysym.sym,
|
keypress(event.key.keysym.sym,
|
||||||
event.key.state == SDL_PRESSED,
|
event.key.state == SDL_PRESSED,
|
||||||
event.key.keysym.unicode);
|
event.key.keysym.sym);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SDL_MOUSEMOTION:
|
case SDL_MOUSEMOTION:
|
||||||
if (ignore) {
|
if (ignore) {
|
||||||
ignore--;
|
ignore--;
|
||||||
break;
|
break;
|
||||||
};
|
}
|
||||||
mousemove(event.motion.xrel, event.motion.yrel);
|
mousemove(event.motion.xrel, event.motion.yrel);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
|
@ -126,9 +126,13 @@ COMMANDN(bind, bindkey, ARG_2STR)
|
||||||
void
|
void
|
||||||
saycommand(char *init) // turns input to the command line on or off
|
saycommand(char *init) // turns input to the command line on or off
|
||||||
{
|
{
|
||||||
SDL_EnableUNICODE(saycommandon = (init != NULL));
|
saycommandon = (init != NULL);
|
||||||
|
if (saycommandon)
|
||||||
|
SDL_StartTextInput();
|
||||||
|
else
|
||||||
|
SDL_StopTextInput();
|
||||||
if (!editmode)
|
if (!editmode)
|
||||||
keyrepeat(saycommandon);
|
keyrepeat = saycommandon;
|
||||||
if (!init)
|
if (!init)
|
||||||
init = "";
|
init = "";
|
||||||
strcpy_s(commandbuf, init);
|
strcpy_s(commandbuf, init);
|
||||||
|
@ -144,52 +148,12 @@ mapmsg(OFString *s)
|
||||||
}
|
}
|
||||||
COMMAND(mapmsg, ARG_1STR)
|
COMMAND(mapmsg, ARG_1STR)
|
||||||
|
|
||||||
#if !defined(OF_WINDOWS) && !defined(OF_MACOS)
|
|
||||||
# include <SDL_syswm.h>
|
|
||||||
# include <X11/Xlib.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void
|
void
|
||||||
pasteconsole()
|
pasteconsole()
|
||||||
{
|
{
|
||||||
#if defined(OF_WINDOWS)
|
char *cb = SDL_GetClipboardText();
|
||||||
if (!IsClipboardFormatAvailable(CF_TEXT))
|
|
||||||
return;
|
|
||||||
if (!OpenClipboard(NULL))
|
|
||||||
return;
|
|
||||||
char *cb = (char *)GlobalLock(GetClipboardData(CF_TEXT));
|
|
||||||
strcat_s(commandbuf, cb);
|
strcat_s(commandbuf, cb);
|
||||||
GlobalUnlock(cb);
|
}
|
||||||
CloseClipboard();
|
|
||||||
#elif !defined(OF_MACOS)
|
|
||||||
SDL_SysWMinfo wminfo;
|
|
||||||
SDL_VERSION(&wminfo.version);
|
|
||||||
wminfo.subsystem = SDL_SYSWM_X11;
|
|
||||||
if (!SDL_GetWMInfo(&wminfo))
|
|
||||||
return;
|
|
||||||
int cbsize;
|
|
||||||
char *cb = XFetchBytes(wminfo.info.x11.display, &cbsize);
|
|
||||||
if (!cb || !cbsize)
|
|
||||||
return;
|
|
||||||
int commandlen = strlen(commandbuf);
|
|
||||||
for (char *cbline = cb, *cbend;
|
|
||||||
commandlen + 1 < _MAXDEFSTR && cbline < &cb[cbsize];
|
|
||||||
cbline = cbend + 1) {
|
|
||||||
cbend = (char *)memchr(cbline, '\0', &cb[cbsize] - cbline);
|
|
||||||
if (!cbend)
|
|
||||||
cbend = &cb[cbsize];
|
|
||||||
if (commandlen + cbend - cbline + 1 > _MAXDEFSTR)
|
|
||||||
cbend = cbline + _MAXDEFSTR - commandlen - 1;
|
|
||||||
memcpy(&commandbuf[commandlen], cbline, cbend - cbline);
|
|
||||||
commandlen += cbend - cbline;
|
|
||||||
commandbuf[commandlen] = '\n';
|
|
||||||
if (commandlen + 1 < _MAXDEFSTR && cbend < &cb[cbsize])
|
|
||||||
++commandlen;
|
|
||||||
commandbuf[commandlen] = '\0';
|
|
||||||
};
|
|
||||||
XFree(cb);
|
|
||||||
#endif
|
|
||||||
};
|
|
||||||
|
|
||||||
cvector vhistory;
|
cvector vhistory;
|
||||||
int histpos = 0;
|
int histpos = 0;
|
||||||
|
|
|
@ -68,8 +68,8 @@ toggleedit()
|
||||||
monsterclear(); // all monsters back at their spawns for
|
monsterclear(); // all monsters back at their spawns for
|
||||||
// editing
|
// editing
|
||||||
projreset();
|
projreset();
|
||||||
};
|
}
|
||||||
keyrepeat(editmode);
|
keyrepeat = editmode;
|
||||||
selset = false;
|
selset = false;
|
||||||
editing = editmode;
|
editing = editmode;
|
||||||
}
|
}
|
||||||
|
|
|
@ -142,7 +142,8 @@ extern int isoccluded(float vx, float vy, float cx, float cy, float csize);
|
||||||
// main
|
// main
|
||||||
extern void fatal(OFString *s, OFString *o = @"");
|
extern void fatal(OFString *s, OFString *o = @"");
|
||||||
extern void *alloc(int s);
|
extern void *alloc(int s);
|
||||||
extern void keyrepeat(bool on);
|
extern SDL_Window *window;
|
||||||
|
extern bool keyrepeat;
|
||||||
|
|
||||||
// rendertext
|
// rendertext
|
||||||
extern void draw_text(char *str, int left, int top, int gl_num);
|
extern void draw_text(char *str, int left, int top, int gl_num);
|
||||||
|
|
|
@ -239,7 +239,7 @@ renderstripssky()
|
||||||
glBindTexture(GL_TEXTURE_2D, skyoglid);
|
glBindTexture(GL_TEXTURE_2D, skyoglid);
|
||||||
loopv(strips) if (strips[i].tex == skyoglid)
|
loopv(strips) if (strips[i].tex == skyoglid)
|
||||||
glDrawArrays(GL_TRIANGLE_STRIP, strips[i].start, strips[i].num);
|
glDrawArrays(GL_TRIANGLE_STRIP, strips[i].start, strips[i].num);
|
||||||
};
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
renderstrips()
|
renderstrips()
|
||||||
|
@ -250,17 +250,17 @@ renderstrips()
|
||||||
if (strips[i].tex != lasttex) {
|
if (strips[i].tex != lasttex) {
|
||||||
glBindTexture(GL_TEXTURE_2D, strips[i].tex);
|
glBindTexture(GL_TEXTURE_2D, strips[i].tex);
|
||||||
lasttex = strips[i].tex;
|
lasttex = strips[i].tex;
|
||||||
};
|
}
|
||||||
glDrawArrays(GL_TRIANGLE_STRIP, strips[i].start, strips[i].num);
|
glDrawArrays(GL_TRIANGLE_STRIP, strips[i].start, strips[i].num);
|
||||||
};
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
overbright(float amount)
|
overbright(float amount)
|
||||||
{
|
{
|
||||||
if (hasoverbright)
|
if (hasoverbright)
|
||||||
glTexEnvf(GL_TEXTURE_ENV, GL_RGB_SCALE_EXT, amount);
|
glTexEnvf(GL_TEXTURE_ENV, GL_RGB_SCALE_EXT, amount);
|
||||||
};
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
addstrip(int tex, int start, int n)
|
addstrip(int tex, int start, int n)
|
||||||
|
@ -269,16 +269,20 @@ addstrip(int tex, int start, int n)
|
||||||
s.tex = tex;
|
s.tex = tex;
|
||||||
s.start = start;
|
s.start = start;
|
||||||
s.num = n;
|
s.num = n;
|
||||||
};
|
}
|
||||||
|
|
||||||
VARFP(gamma, 30, 100, 300, {
|
VARFP(gamma, 30, 100, 300, {
|
||||||
float f = gamma / 100.0f;
|
float f = gamma / 100.0f;
|
||||||
if (SDL_SetGamma(f, f, f) == -1) {
|
Uint16 ramp[256];
|
||||||
|
|
||||||
|
SDL_CalculateGammaRamp(f, ramp);
|
||||||
|
|
||||||
|
if (SDL_SetWindowGammaRamp(window, ramp, ramp, ramp) == -1) {
|
||||||
conoutf(
|
conoutf(
|
||||||
@"Could not set gamma (card/driver doesn't support it?)");
|
@"Could not set gamma (card/driver doesn't support it?)");
|
||||||
conoutf(@"sdl: %s", SDL_GetError());
|
conoutf(@"sdl: %s", SDL_GetError());
|
||||||
};
|
}
|
||||||
});
|
})
|
||||||
|
|
||||||
void
|
void
|
||||||
transplayer()
|
transplayer()
|
||||||
|
|
|
@ -60,23 +60,25 @@ resolverinit(int threads, int limit)
|
||||||
resolverthread &rt = resolverthreads.add();
|
resolverthread &rt = resolverthreads.add();
|
||||||
rt.query = NULL;
|
rt.query = NULL;
|
||||||
rt.starttime = 0;
|
rt.starttime = 0;
|
||||||
rt.thread = SDL_CreateThread(resolverloop, &rt);
|
rt.thread =
|
||||||
|
SDL_CreateThread(resolverloop, "resolverthread", &rt);
|
||||||
--threads;
|
--threads;
|
||||||
};
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
resolverstop(resolverthread &rt, bool restart)
|
resolverstop(resolverthread &rt, bool restart)
|
||||||
{
|
{
|
||||||
SDL_LockMutex(resolvermutex);
|
SDL_LockMutex(resolvermutex);
|
||||||
SDL_KillThread(rt.thread);
|
// SDL_KillThread(rt.thread);
|
||||||
rt.query = NULL;
|
rt.query = NULL;
|
||||||
rt.starttime = 0;
|
rt.starttime = 0;
|
||||||
rt.thread = NULL;
|
rt.thread = NULL;
|
||||||
if (restart)
|
if (restart)
|
||||||
rt.thread = SDL_CreateThread(resolverloop, &rt);
|
rt.thread =
|
||||||
|
SDL_CreateThread(resolverloop, "resolverthread", &rt);
|
||||||
SDL_UnlockMutex(resolvermutex);
|
SDL_UnlockMutex(resolvermutex);
|
||||||
};
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
resolverclear()
|
resolverclear()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue