Merge post-0.7.0 commits through 'c8250d8b8' into v0.7.2.

sdl_common.c has lost some commits in the restructuring and those
will need to be replayed over the restructured files for SDL1 and 2.
This commit is contained in:
Michael Martin
2020-04-03 17:43:49 -07:00
597 changed files with 10714 additions and 5297 deletions
+5 -2
View File
@@ -1,4 +1,6 @@
uqm_SUBDIRS="libs res uqm"
uqm_CFILES="options.c port.c uqm.c"
uqm_HFILES="config.h endian_uqm.h options.h port.h types.h uqmversion.h"
if [ "$uqm_HAVE_GETOPT_LONG" = 0 ]; then
uqm_SUBDIRS="$uqm_SUBDIRS getopt"
@@ -8,11 +10,12 @@ case "$HOST_SYSTEM" in
Darwin)
uqm_SUBDIRS="$uqm_SUBDIRS darwin"
;;
MSVC)
uqm_HFILES="$uqm_HFILES config_vc6.h"
;;
esac
if [ "$uqm_HAVE_REGEX" = 0 ]; then
uqm_SUBDIRS="$uqm_SUBDIRS regex"
fi
uqm_CFILES="options.c port.c uqm.c"
+1 -1
View File
@@ -1,2 +1,2 @@
uqm_MFILES="SDLMain.m"
uqm_HFILES="SDLMain.h"
+8 -11
View File
@@ -1,19 +1,16 @@
/* SDLMain.m - main entry point for our Cocoa-ized SDL app
Initial Version: Darrell Walisser <dwaliss1@purdue.edu>
Non-NIB-Code & other changes: Max Horn <max@quendi.de>
/* SDLMain.m - main entry point for our Cocoa-ized SDL app
Initial Version: Darrell Walisser <dwaliss1@purdue.edu>
Non-NIB-Code & other changes: Max Horn <max@quendi.de>
Feel free to customize this file to suit your needs
Feel free to customize this file to suit your needs
*/
#import <Cocoa/Cocoa.h>
#ifndef _SDLMain_h_
#define _SDLMain_h_
/* An internal Apple class used to setup Apple menus */
@interface NSAppleMenuController:NSObject {}
- (void)controlMenu:(NSMenu *)aMenu;
@end
#import <Cocoa/Cocoa.h>
@interface SDLMain : NSObject
@end
@interface SDLApplication : NSApplication
@end
#endif /* _SDLMain_h_ */
+309 -193
View File
@@ -1,11 +1,8 @@
/* SDLMain.m - main entry point for our Cocoa-ized SDL app
Initial Version: Darrell Walisser <dwaliss1@purdue.edu>
Non-NIB-Code & other changes: Max Horn <max@quendi.de>
/* SDLMain.m - main entry point for our Cocoa-ized SDL app
Initial Version: Darrell Walisser <dwaliss1@purdue.edu>
Non-NIB-Code & other changes: Max Horn <max@quendi.de>
Feel free to customize this file to suit your needs
Modified for use with The Ur-Quan Masters by Nicolas Simonds
<uqm at submedia dot net>
Feel free to customize this file to suit your needs
*/
#import "port.h"
@@ -35,254 +32,373 @@ static BOOL gFinderLaunch;
(void) sender; /* Get rid of unused variable warning */
}
/* override NSApplication:sendEvent, to keep Cocoa from beeping on
non-command keystrokes */
- (void)sendEvent:(NSEvent *)anEvent {
if (NSKeyDown == [anEvent type] || NSKeyUp == [anEvent type]) {
if ([anEvent modifierFlags] & NSCommandKeyMask)
[super sendEvent: anEvent];
} else
[super sendEvent: anEvent];
/* For some reaon, Apple removed setAppleMenu from the headers in 10.4,
but the method still is there and works. To avoid warnings, we declare
it ourselves here. */
@interface NSApplication(SDL_Missing_Methods)
- (void)setAppleMenu:(NSMenu *)menu;
@end
/* Use this flag to determine whether we use SDLMain.nib or not */
#define SDL_USE_NIB_FILE 0
/* Use this flag to determine whether we use CPS (docking) or not */
#define SDL_USE_CPS 1
#ifdef SDL_USE_CPS
/* Portions of CPS.h */
typedef struct CPSProcessSerNum
{
UInt32 lo;
UInt32 hi;
} CPSProcessSerNum;
extern OSErr CPSGetCurrentProcess( CPSProcessSerNum *psn);
extern OSErr CPSEnableForegroundOperation( CPSProcessSerNum *psn, UInt32 _arg2, UInt32 _arg3, UInt32 _arg4, UInt32 _arg5);
extern OSErr CPSSetFrontProcess( CPSProcessSerNum *psn);
#endif /* SDL_USE_CPS */
static int gArgc;
static char **gArgv;
static BOOL gFinderLaunch;
static BOOL gCalledAppMainline = FALSE;
static NSString *getApplicationName(void)
{
const NSDictionary *dict;
NSString *appName = 0;
/* Determine the application name */
dict = (const NSDictionary *)CFBundleGetInfoDictionary(CFBundleGetMainBundle());
if (dict)
appName = [dict objectForKey: @"CFBundleName"];
if (![appName length])
appName = [[NSProcessInfo processInfo] processName];
return appName;
}
#if SDL_USE_NIB_FILE
/* A helper category for NSString */
@interface NSString (ReplaceSubString)
- (NSString *)stringByReplacingRange:(NSRange)aRange with:(NSString *)aString;
@end
#endif
@interface NSApplication (SDLApplication)
@end
@implementation NSApplication (SDLApplication)
/* Invoked from the Quit menu item */
- (void)terminate:(id)sender
{
/* Post a SDL_QUIT event */
SDL_Event event;
event.type = SDL_QUIT;
SDL_PushEvent(&event);
}
@end
/* The main class of the application, the application's delegate */
@implementation SDLMain
static char *
basename (char *path)
{
char *base;
base = strrchr (path, '/');
if (base == NULL)
return path;
return (base + 1);
}
/* Set the working directory to the .app's parent directory */
- (void) setupWorkingDirectory:(BOOL)shouldChdir
{
char origindir[PATH_MAX];
char *c;
if (!shouldChdir)
return;
strncpy (origindir, gArgv[0], sizeof origindir);
origindir[sizeof origindir - 1] = '\0';
c = basename (origindir);
if (c == origindir)
strcpy (origindir, ".");
else
*c = '\0';
/* chdir to the binary app's point of origin */
if (chdir (origindir) != 0)
abort ();
/* then chdir to the .app's parent */
if ( chdir ("../Resources/") != 0 )
abort();
if (shouldChdir)
{
char parentdir[MAXPATHLEN];
CFURLRef url = CFBundleCopyBundleURL(CFBundleGetMainBundle());
CFURLRef url2 = CFURLCreateCopyDeletingLastPathComponent(0, url);
if (CFURLGetFileSystemRepresentation(url2, 1, (UInt8 *)parentdir, MAXPATHLEN)) {
chdir(parentdir); /* chdir to the binary app's parent */
}
CFRelease(url);
CFRelease(url2);
}
}
void
setupAppleMenu (void)
#if SDL_USE_NIB_FILE
/* Fix menu to contain the real app name instead of "SDL App" */
- (void)fixMenu:(NSMenu *)aMenu withAppName:(NSString *)appName
{
NSMenu *appleMenu;
NSRange aRange;
NSEnumerator *enumerator;
NSMenuItem *menuItem;
NSMenuItem *menuItem;
NSString *title;
NSString *appName;
aRange = [[aMenu title] rangeOfString:@"SDL App"];
if (aRange.length != 0)
[aMenu setTitle: [[aMenu title] stringByReplacingRange:aRange with:appName]];
appName = [NSString stringWithUTF8String:basename (gArgv[0])];
appleMenu = [[NSMenu alloc] initWithTitle:appName];
enumerator = [[aMenu itemArray] objectEnumerator];
while ((menuItem = [enumerator nextObject]))
{
aRange = [[menuItem title] rangeOfString:@"SDL App"];
if (aRange.length != 0)
[menuItem setTitle: [[menuItem title] stringByReplacingRange:aRange with:appName]];
if ([menuItem hasSubmenu])
[self fixMenu:[menuItem submenu] withAppName:appName];
}
}
/* Add menu items */
title = [@"Hide " stringByAppendingString:appName];
[appleMenu addItemWithTitle:title action:@selector(hide:)
keyEquivalent:@"h"];
#else
menuItem = (NSMenuItem *)[appleMenu addItemWithTitle:@"Hide Others"
action:@selector(hideOtherApplications:)
keyEquivalent:@"h"];
[menuItem setKeyEquivalentModifierMask:(NSAlternateKeyMask|NSCommandKeyMask)];
static void setApplicationMenu(void)
{
/* warning: this code is very odd */
NSMenu *appleMenu;
NSMenuItem *menuItem;
NSString *title;
NSString *appName;
appName = getApplicationName();
appleMenu = [[NSMenu alloc] initWithTitle:@""];
/* Add menu items */
title = [@"About " stringByAppendingString:appName];
[appleMenu addItemWithTitle:title action:@selector(orderFrontStandardAboutPanel:) keyEquivalent:@""];
[appleMenu addItemWithTitle:@"Show All"
action:@selector(unhideAllApplications:)
keyEquivalent:@""];
[appleMenu addItem:[NSMenuItem separatorItem]];
[appleMenu addItem:[NSMenuItem separatorItem]];
title = [@"Hide " stringByAppendingString:appName];
[appleMenu addItemWithTitle:title action:@selector(hide:) keyEquivalent:@"h"];
title = [@"Quit " stringByAppendingString:appName];
[appleMenu addItemWithTitle:title action:@selector(terminate:)
keyEquivalent:@"q"];
menuItem = (NSMenuItem *)[appleMenu addItemWithTitle:@"Hide Others" action:@selector(hideOtherApplications:) keyEquivalent:@"h"];
[menuItem setKeyEquivalentModifierMask:(NSAlternateKeyMask|NSCommandKeyMask)];
/* Put menu into the menubar */
menuItem = [[NSMenuItem alloc] initWithTitle:@"" action:nil
keyEquivalent:@""];
[menuItem setSubmenu:appleMenu];
[[NSApp mainMenu] addItem:menuItem];
[appleMenu addItemWithTitle:@"Show All" action:@selector(unhideAllApplications:) keyEquivalent:@""];
/* Tell the application object that this is now the application menu */
[NSApp setAppleMenu:appleMenu];
[appleMenu addItem:[NSMenuItem separatorItem]];
/* Finally give up our references to the objects */
[appleMenu release];
[menuItem release];
title = [@"Quit " stringByAppendingString:appName];
[appleMenu addItemWithTitle:title action:@selector(terminate:) keyEquivalent:@"q"];
/* Put menu into the menubar */
menuItem = [[NSMenuItem alloc] initWithTitle:@"" action:nil keyEquivalent:@""];
[menuItem setSubmenu:appleMenu];
[[NSApp mainMenu] addItem:menuItem];
/* Tell the application object that this is now the application menu */
[NSApp setAppleMenu:appleMenu];
/* Finally give up our references to the objects */
[appleMenu release];
[menuItem release];
}
/* Create a window menu */
void
setupWindowMenu (void)
static void setupWindowMenu(void)
{
NSMenu *windowMenu;
NSMenuItem *windowMenuItem;
NSMenuItem *menuItem;
NSMenu *windowMenu;
NSMenuItem *windowMenuItem;
NSMenuItem *menuItem;
windowMenu = [[NSMenu alloc] initWithTitle:@"Window"];
windowMenu = [[NSMenu alloc] initWithTitle:@"Window"];
/* "Minimize" item */
menuItem = [[NSMenuItem alloc] initWithTitle:@"Minimize" action:@selector(performMiniaturize:) keyEquivalent:@"m"];
[windowMenu addItem:menuItem];
[menuItem release];
/* Put menu into the menubar */
windowMenuItem = [[NSMenuItem alloc] initWithTitle:@"Window" action:nil keyEquivalent:@""];
[windowMenuItem setSubmenu:windowMenu];
[[NSApp mainMenu] addItem:windowMenuItem];
/* Tell the application object that this is now the window menu */
[NSApp setWindowsMenu:windowMenu];
/* "Minimize" item */
menuItem = [[NSMenuItem alloc] initWithTitle:@"Minimize"
action:@selector(performMiniaturize:)
keyEquivalent:@"m"];
[windowMenu addItem:menuItem];
[menuItem release];
/* Put menu into the menubar */
windowMenuItem = [[NSMenuItem alloc] initWithTitle:@"Window"
action:nil keyEquivalent:@""];
[windowMenuItem setSubmenu:windowMenu];
[[NSApp mainMenu] addItem:windowMenuItem];
/* Tell the application object that this is now the window menu */
[NSApp setWindowsMenu:windowMenu];
/* Finally give up our references to the objects */
[windowMenu release];
[windowMenuItem release];
/* Finally give up our references to the objects */
[windowMenu release];
[windowMenuItem release];
}
/* Replacement for NSApplicationMain */
void
CustomApplicationMain (int argc, char **argv)
static void CustomApplicationMain (int argc, char **argv)
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
SDLMain *sdlMain;
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
SDLMain *sdlMain;
/* Ensure the application object is initialised */
[SDLApplication sharedApplication];
/* Ensure the application object is initialised */
[NSApplication sharedApplication];
#ifdef SDL_USE_CPS
{
CPSProcessSerNum PSN;
/* Tell the dock about us */
if (!CPSGetCurrentProcess(&PSN))
if (!CPSEnableForegroundOperation(&PSN,0x03,0x3C,0x2C,0x1103))
if (!CPSSetFrontProcess(&PSN))
[NSApplication sharedApplication];
}
#endif /* SDL_USE_CPS */
/* Set up the menubar */
[NSApp setMainMenu:[[NSMenu alloc] init]];
setupAppleMenu ();
setupWindowMenu ();
/* Set up the menubar */
[NSApp setMainMenu:[[NSMenu alloc] init]];
setApplicationMenu();
setupWindowMenu();
/* Create SDLMain and make it the app delegate */
sdlMain = [[SDLMain alloc] init];
[NSApp setDelegate:sdlMain];
/* Start the main event loop */
[NSApp run];
[sdlMain release];
[pool release];
(void) argc; /* Get rid of unused variable warning */
(void) argv; /* Get rid of unused variable warning */
/* Create SDLMain and make it the app delegate */
sdlMain = [[SDLMain alloc] init];
[NSApp setDelegate:sdlMain];
/* Start the main event loop */
[NSApp run];
[sdlMain release];
[pool release];
}
#endif
/*
* Catch document open requests...this lets us notice files when the app
* was launched by double-clicking a document, or when a document was
* dragged/dropped on the app's icon. You need to have a
* CFBundleDocumentsType section in your Info.plist to get this message,
* apparently.
*
* Files are added to gArgv, so to the app, they'll look like command line
* arguments. Previously, apps launched from the finder had nothing but
* an argv[0].
*
* This message may be received multiple times to open several docs on launch.
*
* This message is ignored once the app's mainline has been called.
*/
- (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename
{
const char *temparg;
size_t arglen;
char *arg;
char **newargv;
if (!gFinderLaunch) /* MacOS is passing command line args. */
return FALSE;
if (gCalledAppMainline) /* app has started, ignore this document. */
return FALSE;
temparg = [filename UTF8String];
arglen = SDL_strlen(temparg) + 1;
arg = (char *) SDL_malloc(arglen);
if (arg == NULL)
return FALSE;
newargv = (char **) realloc(gArgv, sizeof (char *) * (gArgc + 2));
if (newargv == NULL)
{
SDL_free(arg);
return FALSE;
}
gArgv = newargv;
SDL_strlcpy(arg, temparg, arglen);
gArgv[gArgc++] = arg;
gArgv[gArgc] = NULL;
return TRUE;
}
/* Called when the internal event loop has just started running */
- (void) applicationDidFinishLaunching: (NSNotification *) note
{
int status;
int status;
/* Set the working directory to the .app's parent directory */
[self setupWorkingDirectory:gFinderLaunch];
/* Set the working directory to the .app's parent directory */
[self setupWorkingDirectory:gFinderLaunch];
/* allow Cocoa to hear keystrokes like Command-Q, etc. */
setenv ("SDL_ENABLEAPPEVENTS", "1", 1);
#if SDL_USE_NIB_FILE
/* Set the main menu to contain the real app name instead of "SDL App" */
[self fixMenu:[NSApp mainMenu] withAppName:getApplicationName()];
#endif
/* Hand off to main application code */
status = SDL_main (gArgc, gArgv);
/* Hand off to main application code */
gCalledAppMainline = TRUE;
status = SDL_main (gArgc, gArgv);
/* We're done, thank you for playing */
exit (status);
(void) note; /* Get rid of unused variable warning */
/* We're done, thank you for playing */
exit(status);
}
@end
@implementation NSString (ReplaceSubString)
- (NSString *) stringByReplacingRange:(NSRange)aRange with:(NSString *)aString
- (NSString *)stringByReplacingRange:(NSRange)aRange with:(NSString *)aString
{
unsigned int bufferSize;
unsigned int selfLen = [self length];
unsigned int aStringLen = [aString length];
unichar *buffer;
NSRange localRange;
NSString *result;
unsigned int bufferSize;
unsigned int selfLen = [self length];
unsigned int aStringLen = [aString length];
unichar *buffer;
NSRange localRange;
NSString *result;
bufferSize = selfLen + aStringLen - aRange.length;
buffer = NSAllocateMemoryPages (bufferSize * sizeof (unichar));
/* Get first part into buffer */
localRange.location = 0;
localRange.length = aRange.location;
[self getCharacters:buffer range:localRange];
/* Get middle part into buffer */
localRange.location = 0;
localRange.length = aStringLen;
[aString getCharacters:(buffer + aRange.location) range:localRange];
/* Get last part into buffer */
localRange.location = aRange.location + aRange.length;
localRange.length = selfLen - localRange.location;
[self getCharacters:(buffer + aRange.location+aStringLen)
range:localRange];
/* Build output string */
result = [NSString stringWithCharacters:buffer length:bufferSize];
NSDeallocateMemoryPages (buffer, bufferSize);
return result;
bufferSize = selfLen + aStringLen - aRange.length;
buffer = (unichar *)NSAllocateMemoryPages(bufferSize*sizeof(unichar));
/* Get first part into buffer */
localRange.location = 0;
localRange.length = aRange.location;
[self getCharacters:buffer range:localRange];
/* Get middle part into buffer */
localRange.location = 0;
localRange.length = aStringLen;
[aString getCharacters:(buffer+aRange.location) range:localRange];
/* Get last part into buffer */
localRange.location = aRange.location + aRange.length;
localRange.length = selfLen - localRange.location;
[self getCharacters:(buffer+aRange.location+aStringLen) range:localRange];
/* Build output string */
result = [NSString stringWithCharacters:buffer length:bufferSize];
NSDeallocateMemoryPages(buffer, bufferSize);
return result;
}
@end
#ifdef main
# undef main
#endif
/* Main entry point to executable - should *not* be SDL_main! */
int
main (int argc, char **argv)
int main (int argc, char **argv)
{
/* Copy the arguments into a global variable */
int i;
/* Copy the arguments into a global variable */
/* This is passed if we are launched by double-clicking */
if ( argc >= 2 && strncmp (argv[1], "-psn", 4) == 0 ) {
gArgv = (char **) SDL_malloc(sizeof (char *) * 2);
gArgv[0] = argv[0];
gArgv[1] = NULL;
gArgc = 1;
gFinderLaunch = YES;
} else {
int i;
gArgc = argc;
gArgv = (char **) SDL_malloc(sizeof (char *) * (argc+1));
for (i = 0; i <= argc; i++)
gArgv[i] = argv[i];
gFinderLaunch = NO;
}
/* If we are launched by double-clicking, argv[1] is "-psn_<some_number> */
if ( argc >= 2 && strncmp (argv[1], "-psn_", 5) == 0 ) {
gArgc = 1;
gFinderLaunch = YES;
} else {
gArgc = argc;
gFinderLaunch = NO;
}
gArgv = (char **) malloc (sizeof *gArgv * (gArgc + 1));
if (gArgv == NULL)
abort ();
for (i = 0; i < gArgc; i++)
gArgv[i] = argv[i];
gArgv[i] = NULL;
CustomApplicationMain (argc, argv);
free (gArgv);
return 0;
#if SDL_USE_NIB_FILE
NSApplicationMain (argc, argv);
#else
CustomApplicationMain (argc, argv);
#endif
return 0;
}
#endif
+9
View File
@@ -61,6 +61,11 @@
#define UQM_Swap32 __arch__swab32
#endif
#endif /* linux */
#if defined(__cplusplus)
extern "C" {
#endif
/* Use inline functions for compilers that support them, and static
functions for those that do not. Because these functions become
static for compilers that do not support inline functions, this
@@ -124,4 +129,8 @@ static __inline__ uint64 UQM_Swap64(uint64 val)
#define UQM_SwapBE64(X) (X)
#endif
#if defined(__cplusplus)
}
#endif
#endif /* _ENDIAN_H */
+1
View File
@@ -1 +1,2 @@
uqm_CFILES="getopt.c getopt1.c"
uqm_HFILES="getopt.h"
+5
View File
@@ -12,3 +12,8 @@ fi
# uqm_SUBDIRS="$UQM_SUBDIRS debug"
#fi
uqm_HFILES="alarm.h async.h callback.h cdplib.h compiler.h declib.h file.h
gfxlib.h heap.h inplib.h list.h log.h mathlib.h md5.h memlib.h
misc.h net.h platform.h reslib.h sndlib.h strlib.h tasklib.h
threadlib.h timelib.h uio.h uioutils.h unicode.h vidlib.h"
+7
View File
@@ -1,2 +1,9 @@
#if defined(__cplusplus)
extern "C" {
#endif
#include "callback/alarm.h"
#if defined(__cplusplus)
}
#endif
+10
View File
@@ -0,0 +1,10 @@
#if defined(__cplusplus)
extern "C" {
#endif
#include "callback/async.h"
#if defined(__cplusplus)
}
#endif
+8
View File
@@ -1,2 +1,10 @@
#if defined(__cplusplus)
extern "C" {
#endif
#include "callback/callback.h"
#if defined(__cplusplus)
}
#endif
+2 -2
View File
@@ -1,2 +1,2 @@
uqm_CFILES="alarm.c callback.c"
uqm_CFILES="alarm.c async.c callback.c"
uqm_HFILES="alarm.h async.h callback.h"
+50 -7
View File
@@ -18,6 +18,7 @@
#include "alarm.h"
#include SDL_INCLUDE(SDL.h)
#include "libs/heap.h"
#include <assert.h>
@@ -71,19 +72,36 @@ Alarm_uninit(void) {
}
static inline AlarmTime
AlarmTime_nowMS(void) {
AlarmTime_nowMs(void) {
return SDL_GetTicks();
}
Alarm *
Alarm_addRelativeMs(Uint32 ms, AlarmCallback callback,
Alarm_addAbsoluteMs(uint32 ms, AlarmCallback callback,
AlarmCallbackArg arg) {
Alarm *alarm;
assert(alarmHeap != NULL);
alarm = Alarm_alloc();
alarm->time = AlarmTime_nowMS() + ms;
alarm->time = ms;
alarm->callback = callback;
alarm->arg = arg;
Heap_add(alarmHeap, (HeapValue *) alarm);
return alarm;
}
Alarm *
Alarm_addRelativeMs(uint32 ms, AlarmCallback callback,
AlarmCallbackArg arg) {
Alarm *alarm;
assert(alarmHeap != NULL);
alarm = Alarm_alloc();
alarm->time = AlarmTime_nowMs() + ms;
alarm->callback = callback;
alarm->arg = arg;
@@ -99,15 +117,40 @@ Alarm_remove(Alarm *alarm) {
Alarm_free(alarm);
}
// Process at most one alarm, if its time has come.
// It is safe to call this function again from inside a callback function
// that it called. It should not be called from multiple threads at once.
bool
Alarm_processOne(void)
{
AlarmTime now;
Alarm *alarm;
assert(alarmHeap != NULL);
if (!Heap_hasMore(alarmHeap))
return false;
now = AlarmTime_nowMs();
alarm = (Alarm *) Heap_first(alarmHeap);
if (now < alarm->time)
return false;
Heap_pop(alarmHeap);
alarm->callback(alarm->arg);
Alarm_free(alarm);
return true;
}
#if 0
// It is safe to call this function again from inside a callback function
// that it called. It should not be called from multiple threads at once.
void
Alarm_process(void) {
Alarm_processAll(void) {
AlarmTime now;
assert(alarmHeap != NULL);
now = AlarmTime_nowMS();
now = AlarmTime_nowMs();
while (Heap_hasMore(alarmHeap)) {
Alarm *alarm = (Alarm *) Heap_first(alarmHeap);
@@ -119,8 +162,9 @@ Alarm_process(void) {
Alarm_free(alarm);
}
}
#endif
Uint32
uint32
Alarm_timeBeforeNextMs(void) {
Alarm *alarm;
@@ -131,4 +175,3 @@ Alarm_timeBeforeNextMs(void) {
return alarmTimeToMsUint32(alarm->time);
}
+9 -7
View File
@@ -22,11 +22,10 @@
#include "port.h"
#include "types.h"
#include SDL_INCLUDE(SDL.h)
typedef Uint32 AlarmTime;
static inline Uint32
typedef uint32 AlarmTime;
static inline uint32
alarmTimeToMsUint32(AlarmTime time) {
return (Uint32) time;
return (uint32) time;
}
typedef struct Alarm Alarm;
@@ -44,11 +43,14 @@ struct Alarm {
void Alarm_init(void);
void Alarm_uninit(void);
Alarm *Alarm_addRelativeMs(Uint32 ms, AlarmCallback callback,
Alarm *Alarm_addAbsoluteMs(uint32 ms, AlarmCallback callback,
AlarmCallbackArg arg);
Alarm *Alarm_addRelativeMs(uint32 ms, AlarmCallback callback,
AlarmCallbackArg arg);
void Alarm_remove(Alarm *alarm);
void Alarm_process(void);
Uint32 Alarm_timeBeforeNextMs(void);
bool Alarm_processOne(void);
void Alarm_processAll(void);
uint32 Alarm_timeBeforeNextMs(void);
#endif /* LIBS_CALLBACK_ALARM_H_ */
+56
View File
@@ -0,0 +1,56 @@
/*
* Copyright 2012 Serge van den Boom <svdb@stack.nl>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "async.h"
#include "libs/alarm.h"
#include "libs/callback.h"
// Process all alarms and callbacks.
// First, all scheduled callbacks are called.
// Then each alarm due is called, and after each of these alarms, the
// callbacks scheduled by this alarm are called.
void
Async_process(void)
{
// Call pending callbacks.
Callback_process();
for (;;) {
if (!Alarm_processOne())
return;
// Call callbacks scheduled from the last alarm.
Callback_process();
}
}
// Returns the next time that some asynchronous callback is
// to be called. Note that all values lower than the current time
// should be considered as 'somewhere in the past'.
uint32
Async_timeBeforeNextMs(void) {
if (Callback_haveMore()) {
// Any time before the current time is ok, though we reserve 0 so
// that the caller may use it as a special value in its own code.
return 1;
}
return Alarm_timeBeforeNextMs();
}
+28
View File
@@ -0,0 +1,28 @@
/*
* Copyright 2012 Serge van den Boom <svdb@stack.nl>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef _ASYNC_H
#define _ASYNC_H
#include "types.h"
void Async_process(void);
uint32 Async_timeBeforeNextMs(void);
#endif /* _ASYNC_H */
+24 -4
View File
@@ -23,6 +23,8 @@
#include <stdlib.h>
#include <sys/types.h>
#include "libs/threadlib.h"
typedef struct CallbackLink CallbackLink;
#define CALLBACK_INTERNAL
@@ -38,16 +40,16 @@ static CallbackLink *callbacks;
static CallbackLink **callbacksEnd;
static CallbackLink *const *callbacksProcessEnd;
static Mutex callbackListLock;
static inline void
CallbackList_lock(void) {
// TODO
// Necessary for reentrant operation
LockMutex(callbackListLock);
}
static inline void
CallbackList_unlock(void) {
// TODO
// Necessary for reentrant operation
UnlockMutex(callbackListLock);
}
#if 0
@@ -62,6 +64,14 @@ Callback_init(void) {
callbacks = NULL;
callbacksEnd = &callbacks;
callbacksProcessEnd = &callbacks;
callbackListLock = CreateMutex("Callback List Lock", SYNC_CLASS_TOPLEVEL);
}
void
Callback_uninit(void) {
// TODO: cleanup the queue?
DestroyMutex (callbackListLock);
callbackListLock = 0;
}
// Callbacks are guaranteed to be called in the order that they are queued.
@@ -170,4 +180,14 @@ Callback_process(void) {
}
}
bool
Callback_haveMore(void) {
bool result;
CallbackList_lock();
result = (callbacks != NULL);
CallbackList_unlock();
return result;
}
+2
View File
@@ -33,9 +33,11 @@ typedef void *CallbackArg;
typedef void (*CallbackFunction)(CallbackArg arg);
void Callback_init(void);
void Callback_uninit(void);
CallbackID Callback_add(CallbackFunction callback, CallbackArg arg);
bool Callback_remove(CallbackID id);
void Callback_process(void);
bool Callback_haveMore(void);
#endif /* LIBS_CALLBACK_CALLBACK_H_ */
+2
View File
@@ -1 +1,3 @@
uqm_CFILES="cdp.c cdpapi.c"
uqm_HFILES="cdp_alli.h cdpapi.h cdp.h cdp_iio.h cdp_imem.h cdpint.h
cdp_isnd.h cdp_ivid.h cdpmod.h windl.h"
+8
View File
@@ -19,6 +19,14 @@
#ifndef LIBS_CDPLIB_H_
#define LIBS_CDPLIB_H_
#if defined(__cplusplus)
extern "C" {
#endif
#include "cdp/cdp.h"
#if defined(__cplusplus)
}
#endif
#endif /* LIBS_CDPLIB_H_ */
+8 -1
View File
@@ -21,6 +21,10 @@
#include "types.h"
#if defined(__cplusplus)
extern "C" {
#endif
typedef uint8 BYTE;
typedef uint8 UBYTE;
typedef sint8 SBYTE;
@@ -85,5 +89,8 @@ typedef DWORD (*PDWORDFUNC) (void);
# define _ALIGNED_ON(bytes)
#endif
#endif /* LIBS_COMPILER_H_ */
#if defined(__cplusplus)
}
#endif
#endif /* LIBS_COMPILER_H_ */
+9
View File
@@ -20,6 +20,11 @@
#define LIBS_DECLIB_H_
#include "libs/compiler.h"
#if defined(__cplusplus)
extern "C" {
#endif
typedef struct _LZHCODE_DESC* DECODE_REF;
enum
@@ -45,4 +50,8 @@ extern COUNT cread (void *pStr, COUNT size, COUNT count,
extern COUNT cwrite (const void *pStr, COUNT size, COUNT count,
DECODE_REF DecodeRef);
#if defined(__cplusplus)
}
#endif
#endif /* LIBS_DECLIB_H_ */
+1
View File
@@ -1 +1,2 @@
uqm_CFILES="lzdecode.c lzencode.c update.c"
uqm_HFILES="lzh.h"
+8
View File
@@ -25,6 +25,10 @@
// for bool
#include "types.h"
#if defined(__cplusplus)
extern "C" {
#endif
#if 0
// from temp.h
void initTempDir (void);
@@ -83,5 +87,9 @@ static inline int isDriveLetter(int c)
}
#endif /* HAVE_DRIVE_LETTERS */
#if defined(__cplusplus)
}
#endif
#endif /* LIBS_FILE_H_ */
+1
View File
@@ -1 +1,2 @@
uqm_CFILES="dirs.c files.c"
uqm_HFILES="filintrn.h"
+8 -4
View File
@@ -142,7 +142,7 @@ mkdirhier (const char *path)
if (*pathstart == '\0') {
// path exists completely, nothing more to do
return 0;
goto success;
}
// walk through the path as long as the components exist
@@ -177,7 +177,7 @@ mkdirhier (const char *path)
}
if (*pathend == '\0')
return 0;
goto success;
*ptr = '/';
ptr++;
@@ -187,7 +187,7 @@ mkdirhier (const char *path)
// pathstart is the next non-slash character
if (*pathstart == '\0')
return 0;
goto success;
}
// create all components left
@@ -221,6 +221,9 @@ mkdirhier (const char *path)
ptr += pathend - pathstart;
*ptr = '\0';
}
success:
HFree (buf);
return 0;
err:
@@ -641,6 +644,7 @@ expandPath (char *dest, size_t len, const char *src, int what)
*destptr = '\0';
}
HFree (buf);
return 0;
err:
@@ -656,7 +660,7 @@ err:
// This code is only needed if we have a current working directory
// per drive.
// letter is 0 based: 0 = A, 1 = B, ...
bool
static bool
driveLetterExists(int letter)
{
unsigned long drives;
+1 -1
View File
@@ -94,7 +94,7 @@ copyFile (uio_DirHandle *srcDir, const char *srcName,
buf = HMalloc(BUFSIZE);
// This was originally a statically allocated buffer,
// but as this function might be run from a thread with
// a small Stack, this is better.
// a small stack, this is better.
while (1)
{
numInBuf = uio_read (src, buf, BUFSIZE);
+17
View File
@@ -32,6 +32,10 @@ struct Color {
#include "libs/reslib.h"
#if defined(__cplusplus)
extern "C" {
#endif
typedef struct context_desc CONTEXT_DESC;
typedef struct frame_desc FRAME_DESC;
typedef struct font_desc FONT_DESC;
@@ -227,8 +231,16 @@ typedef struct text
COUNT CharCount;
} TEXT;
#if defined(__cplusplus)
}
#endif
#include "libs/strlib.h"
#if defined(__cplusplus)
extern "C" {
#endif
typedef STRING_TABLE COLORMAP_REF;
typedef STRING COLORMAP;
// COLORMAPPTR is really a pointer to colortable entry structure
@@ -237,6 +249,7 @@ typedef void *COLORMAPPTR;
#include "graphics/prim.h"
typedef BYTE BATCH_FLAGS;
// This flag is currently unused but it might make sense to restore it
#define BATCH_BUILD_PAGE (BATCH_FLAGS)(1 << 0)
@@ -454,4 +467,8 @@ extern COLORMAPPTR GetColorMapAddress (COLORMAP);
void SetSystemRect (const RECT *pRect);
void ClearSystemRect (void);
#if defined(__cplusplus)
}
#endif
#endif /* LIBS_GFXLIB_H_ */
+3
View File
@@ -7,3 +7,6 @@ uqm_CFILES="boxint.c clipline.c cmap.c context.c drawable.c filegfx.c
font.c frame.c gfx_common.c intersec.c loaddisp.c
pixmap.c resgfx.c tfb_draw.c tfb_prim.c widgets.c"
uqm_HFILES="bbox.h cmap.h context.h dcqueue.h drawable.h drawcmd.h font.h
gfx_common.h gfxintrn.h prim.h tfb_draw.h tfb_prim.h widgets.h"
+25 -5
View File
@@ -64,6 +64,10 @@ static int mapcount;
static Mutex maplock;
static void release_colormap (TFB_ColorMap *map);
static void delete_colormap (TFB_ColorMap *map);
void
InitColorMaps (void)
{
@@ -84,13 +88,23 @@ InitColorMaps (void)
void
UninitColorMaps (void)
{
int i;
TFB_ColorMap *next;
for (i = 0; i < MAX_COLORMAPS; ++i)
{
TFB_ColorMap *map = colormaps[i];
if (!map)
continue;
release_colormap (map);
colormaps[i] = 0;
}
// free spares
for ( ; poolhead; poolhead = next)
for ( ; poolhead; poolhead = next, --poolcount)
{
next = poolhead->next;
HFree (poolhead);
delete_colormap (poolhead);
}
DestroyMutex (fadeLock);
@@ -155,6 +169,13 @@ clone_colormap (TFB_ColorMap *from, int index)
return map;
}
static void
delete_colormap (TFB_ColorMap *map)
{
FreeNativePalette (map->palette);
HFree (map);
}
static inline void
free_colormap (TFB_ColorMap *map)
{
@@ -172,8 +193,7 @@ free_colormap (TFB_ColorMap *map)
}
else
{ // don't need any more spares
FreeNativePalette (map->palette);
HFree (map);
delete_colormap (map);
}
}
@@ -193,7 +213,7 @@ get_colormap (int index)
return map;
}
static inline void
static void
release_colormap (TFB_ColorMap *map)
{
if (!map)
+6
View File
@@ -123,6 +123,8 @@ FindContextPtr (CONTEXT context) {
BOOLEAN
DestroyContext (CONTEXT ContextRef)
{
TFB_Image *img;
if (ContextRef == 0)
return (FALSE);
@@ -139,6 +141,10 @@ DestroyContext (CONTEXT ContextRef)
}
#endif /* DEBUG */
img = ContextRef->FontBacking;
if (img)
TFB_DrawImage_Delete (img);
FreeContext (ContextRef);
return TRUE;
}
+83 -2
View File
@@ -156,8 +156,17 @@ Init_DrawCommandQueue (void)
void
Uninit_DrawCommandQueue (void)
{
DestroyCondVar (RenderingCond);
DestroyRecursiveMutex (DCQ_Mutex);
if (RenderingCond)
{
DestroyCondVar (RenderingCond);
RenderingCond = 0;
}
if (DCQ_Mutex)
{
DestroyRecursiveMutex (DCQ_Mutex);
DCQ_Mutex = 0;
}
}
void
@@ -216,6 +225,30 @@ TFB_DrawCommandQueue_Clear ()
UnlockRecursiveMutex (DCQ_Mutex);
}
static void
checkExclusiveThread (TFB_DrawCommand* DrawCommand)
{
#ifdef DEBUG_DCQ_THREADS
static uint32 exclusiveThreadId;
extern uint32 SDL_ThreadID(void);
// Only one thread is currently allowed to enqueue commands
// This is not a technical limitation but rather a semantical one atm.
if (DrawCommand->Type == TFB_DRAWCOMMANDTYPE_REINITVIDEO)
{ // TFB_DRAWCOMMANDTYPE_REINITVIDEO is an exception
// It is queued from the main() thread, which is safe to do
return;
}
if (!exclusiveThreadId)
exclusiveThreadId = SDL_ThreadID();
else
assert (SDL_ThreadID() == exclusiveThreadId);
#else
(void) DrawCommand; // suppress unused warning
#endif
}
void
TFB_EnqueueDrawCommand (TFB_DrawCommand* DrawCommand)
{
@@ -224,6 +257,8 @@ TFB_EnqueueDrawCommand (TFB_DrawCommand* DrawCommand)
return;
}
checkExclusiveThread (DrawCommand);
if (DrawCommand->Type <= TFB_DRAWCOMMANDTYPE_COPYTOIMAGE
&& _CurFramePtr->Type == SCREEN_DRAWABLE)
{
@@ -587,3 +622,49 @@ TFB_FlushGraphics (void)
RenderedFrames++;
BroadcastCondVar (RenderingCond);
}
void
TFB_PurgeDanglingGraphics (void)
{
Lock_DCQ (-1);
for (;;)
{
TFB_DrawCommand DC;
if (!TFB_DrawCommandQueue_Pop (&DC))
{
// the Queue is now empty.
break;
}
switch (DC.Type)
{
case TFB_DRAWCOMMANDTYPE_DELETEIMAGE:
{
TFB_Image *DC_image = DC.data.deleteimage.image;
TFB_DrawImage_Delete (DC_image);
break;
}
case TFB_DRAWCOMMANDTYPE_DELETEDATA:
{
void *data = DC.data.deletedata.data;
HFree (data);
break;
}
case TFB_DRAWCOMMANDTYPE_IMAGE:
{
TFB_ColorMap *cmap = DC.data.image.colormap;
if (cmap)
TFB_ReturnColorMap (cmap);
break;
}
case TFB_DRAWCOMMANDTYPE_SENDSIGNAL:
{
ClearSemaphore (DC.data.sendsignal.sem);
break;
}
}
}
Unlock_DCQ ();
}
+1 -1
View File
@@ -99,7 +99,7 @@ UnbatchGraphics (void)
been processed. */
void
FlushGraphics ()
FlushGraphics (void)
{
TFB_DrawScreen_WaitForSignal ();
}
+2 -1
View File
@@ -67,7 +67,7 @@ int TFB_InitGraphics (int driver, int flags, int width, int height);
int TFB_ReInitGraphics (int driver, int flags, int width, int height);
void TFB_UninitGraphics (void);
void TFB_ProcessEvents (void);
void TFB_SetGamma (float gamma);
bool TFB_SetGamma (float gamma);
void TFB_UploadTransitionScreen (void);
int TFB_SupportsHardwareScaling (void);
// This function should not be called directly
@@ -99,6 +99,7 @@ extern float FrameRate;
extern int FrameRateTickBase;
void TFB_FlushGraphics (void); // Only call from main thread!!
void TFB_PurgeDanglingGraphics (void); // Only call from main thread as part of shutdown.
extern int ScreenWidth;
extern int ScreenHeight;
+1 -9
View File
@@ -321,15 +321,7 @@ _ReleaseCelData (void *handle)
return (FALSE);
cel_ct = DrawablePtr->MaxIndex + 1;
if (DrawablePtr->Frame)
{
FramePtr = DrawablePtr->Frame;
if (FramePtr->Type == SCREEN_DRAWABLE)
{
FramePtr = NULL;
}
}
FramePtr = DrawablePtr->Frame;
HFree (handle);
if (FramePtr)
+4 -1
View File
@@ -1,6 +1,9 @@
uqm_CFILES="opengl.c palette.c primitives.c pure.c sdl2_pure.c
uqm_CFILES="opengl.c palette.c primitives.c pure.c sdl2_pure.c
sdl_common.c sdl1_common.c sdl2_common.c
scalers.c 2xscalers.c
2xscalers_mmx.c 2xscalers_sse.c 2xscalers_3dnow.c
nearest2x.c bilinear2x.c biadv2x.c triscan2x.c hq2x.c
canvas.c png2sdl.c sdluio.c rotozoom.c"
uqm_HFILES="2xscalers.h 2xscalers_mmx.h opengl.h palette.h png2sdl.h
primitives.h pure.h rotozoom.h scaleint.h scalemmx.h
scalers.h sdl_common.h sdluio.h"
-24
View File
@@ -74,30 +74,6 @@ static TFB_GRAPHICS_BACKEND opengl_unscaled_backend = {
TFB_GL_ColorLayer };
static SDL_Surface *
Create_Screen (SDL_Surface *template, int w, int h)
{
SDL_Surface *newsurf = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h,
template->format->BitsPerPixel,
template->format->Rmask, template->format->Gmask,
template->format->Bmask, 0);
if (newsurf == 0) {
log_add (log_Error, "Couldn't create screen buffers: %s",
SDL_GetError());
}
return newsurf;
}
static int
ReInit_Screen (SDL_Surface **screen, SDL_Surface *template, int w, int h)
{
if (*screen)
SDL_FreeSurface (*screen);
*screen = Create_Screen (template, w, h);
return *screen == 0 ? -1 : 0;
}
static int
AttemptColorDepth (int flags, int width, int height, int bpp)
{
+1
View File
@@ -23,6 +23,7 @@
#if SDL_MAJOR_VERSION == 1
int TFB_GL_InitGraphics (int driver, int flags, int width, int height);
void TFB_GL_UninitGraphics (void);
int TFB_GL_ConfigureVideo (int driver, int flags, int width, int height, int togglefullscreen);
#ifdef HAVE_OPENGL
+8 -24
View File
@@ -53,30 +53,6 @@ static TFB_GRAPHICS_BACKEND pure_unscaled_backend = {
TFB_Pure_ScreenLayer,
TFB_Pure_ColorLayer };
static SDL_Surface *
Create_Screen (SDL_Surface *template, int w, int h)
{
SDL_Surface *newsurf = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h,
template->format->BitsPerPixel,
template->format->Rmask, template->format->Gmask,
template->format->Bmask, 0);
if (newsurf == 0) {
log_add (log_Error, "Couldn't create screen buffers: %s",
SDL_GetError());
}
return newsurf;
}
static int
ReInit_Screen (SDL_Surface **screen, SDL_Surface *template, int w, int h)
{
if (*screen)
SDL_FreeSurface (*screen);
*screen = Create_Screen (template, w, h);
return *screen == 0 ? -1 : 0;
}
// We cannot rely on SDL_DisplayFormatAlpha() anymore. It can return
// formats that we do not expect (SDL v1.2.14 on Mac OSX). Mac likes
// ARGB surfaces, but SDL_DisplayFormatAlpha thinks that only RGBA are fast.
@@ -293,6 +269,14 @@ TFB_Pure_InitGraphics (int driver, int flags, int width, int height)
return 0;
}
void
TFB_Pure_UninitGraphics (void)
{
UnInit_Screen (&scaled_display);
UnInit_Screen (&fade_color_surface);
UnInit_Screen (&fade_temp);
}
static void
ScanLines (SDL_Surface *dst, SDL_Rect *r)
{
+1
View File
@@ -22,6 +22,7 @@
#include "libs/graphics/sdl/sdl_common.h"
int TFB_Pure_InitGraphics (int driver, int flags, int width, int height);
void TFB_Pure_UninitGraphics (void);
int TFB_Pure_ConfigureVideo (int driver, int flags, int width, int height, int togglefullscreen);
void Scale_PerfTest (void);
+6 -2
View File
@@ -223,6 +223,7 @@ int zoomSurfaceRGBA(SDL_Surface * src, SDL_Surface * dst, int smooth)
*/
static
int zoomSurfaceY(SDL_Surface * src, SDL_Surface * dst)
{
Uint32 sx, sy, *sax, *say, *csax, *csay, csx, csy;
@@ -343,6 +344,7 @@ int zoomSurfaceY(SDL_Surface * src, SDL_Surface * dst)
*/
static
void transformSurfaceRGBA(SDL_Surface * src, SDL_Surface * dst, int cx, int cy, int isin, int icos, int smooth)
{
int x, y, t1, t2, dx, dy, xd, yd, sdx, sdy, ax, ay, ex, ey, sw, sh;
@@ -498,6 +500,7 @@ void transformSurfaceRGBA(SDL_Surface * src, SDL_Surface * dst, int cx, int cy,
*/
static
void transformSurfaceY(SDL_Surface * src, SDL_Surface * dst, int cx, int cy, int isin, int icos)
{
int x, y, dx, dy, xd, yd, sdx, sdy, ax, ay, sw, sh;
@@ -560,6 +563,7 @@ void transformSurfaceY(SDL_Surface * src, SDL_Surface * dst, int cx, int cy, int
/* Local rotozoom-size function with trig result return */
static
void rotozoomSurfaceSizeTrig(int width, int height, double angle, double zoom, int *dstwidth, int *dstheight,
double *canglezoom, double *sanglezoom)
{
@@ -581,8 +585,8 @@ void rotozoomSurfaceSizeTrig(int width, int height, double angle, double zoom, i
cy = *canglezoom * y;
sx = *sanglezoom * x;
sy = *sanglezoom * y;
dstwidthhalf = MAX((int) ceil(fabs(cx) + fabs(sy)), 1);
dstheighthalf = MAX((int) ceil(fabs(sx) + fabs(cy)), 1);
dstwidthhalf = MAX(ceil(fabs(cx) + fabs(sy)), 1);
dstheighthalf = MAX(ceil(fabs(sx) + fabs(cy)), 1);
*dstwidth = 2 * dstwidthhalf;
*dstheight = 2 * dstheighthalf;
}
+5 -5
View File
@@ -213,8 +213,8 @@ Scale_PrepPlatform (int flags, const SDL_PixelFormat* fmt)
// first match wins
// add better platform techs to the top
#ifdef MMX_ASM
if ( (!force_platform && (SDL_HasSSE () || SDL_HasMMX ()))
|| force_platform == SCALEPLAT_SSE)
if ( (!force_platform && (SDL_HasSSE () || SDL_HasMMXExt ()))
|| force_platform == PLATFORM_SSE)
{
log_add (log_Info, "Screen scalers are using SSE/MMX-Ext/MMX code");
Scale_Platform = SCALEPLAT_SSE;
@@ -223,7 +223,7 @@ Scale_PrepPlatform (int flags, const SDL_PixelFormat* fmt)
}
else
if ( (!force_platform && SDL_HasAltiVec ())
|| force_platform == SCALEPLAT_ALTIVEC)
|| force_platform == PLATFORM_ALTIVEC)
{
log_add (log_Info, "Screen scalers would use AltiVec code "
"if someone actually wrote it");
@@ -231,7 +231,7 @@ Scale_PrepPlatform (int flags, const SDL_PixelFormat* fmt)
}
else
if ( (!force_platform && SDL_Has3DNow ())
|| force_platform == SCALEPLAT_3DNOW)
|| force_platform == PLATFORM_3DNOW)
{
log_add (log_Info, "Screen scalers are using 3DNow/MMX code");
Scale_Platform = SCALEPLAT_3DNOW;
@@ -240,7 +240,7 @@ Scale_PrepPlatform (int flags, const SDL_PixelFormat* fmt)
}
else
if ( (!force_platform && SDL_HasMMX ())
|| force_platform == SCALEPLAT_MMX)
|| force_platform == PLATFORM_MMX)
{
log_add (log_Info, "Screen scalers are using MMX code");
Scale_Platform = SCALEPLAT_MMX;
+98 -12
View File
@@ -50,18 +50,96 @@ TFB_GRAPHICS_BACKEND *graphics_backend = NULL;
volatile int QuitPosted = 0;
volatile int GameActive = 1; // Track the SDL_ACTIVEEVENT state SDL_APPACTIVE
static void TFB_PreQuit (void);
void
TFB_PreInit (void)
{
log_add (log_Info, "Initializing base SDL functionality.");
log_add (log_Info, "Using SDL version %d.%d.%d (compiled with "
"%d.%d.%d)", SDL_Linked_Version ()->major,
SDL_Linked_Version ()->minor, SDL_Linked_Version ()->patch,
SDL_MAJOR_VERSION, SDL_MINOR_VERSION, SDL_PATCHLEVEL);
#if 0
if (SDL_Linked_Version ()->major != SDL_MAJOR_VERSION ||
SDL_Linked_Version ()->minor != SDL_MINOR_VERSION ||
SDL_Linked_Version ()->patch != SDL_PATCHLEVEL) {
log_add (log_Warning, "The used SDL library is not the same version "
"as the one used to compile The Ur-Quan Masters with! "
"If you experience any crashes, this would be an excellent "
"suspect.");
}
#endif
if ((SDL_Init (SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE) == -1))
{
log_add (log_Fatal, "Could not initialize SDL: %s.", SDL_GetError ());
exit (EXIT_FAILURE);
}
atexit (TFB_PreQuit);
}
static void
TFB_PreQuit (void)
{
SDL_Quit ();
}
int
TFB_ReInitGraphics (int driver, int flags, int width, int height)
{
int result;
int togglefullscreen = 0;
char caption[200];
if (GfxFlags == (flags ^ TFB_GFXFLAGS_FULLSCREEN) &&
driver == GraphicsDriver &&
width == ScreenWidthActual && height == ScreenHeightActual)
{
togglefullscreen = 1;
}
GfxFlags = flags;
if (driver == TFB_GFXDRIVER_SDL_OPENGL)
{
#ifdef HAVE_OPENGL
result = TFB_GL_ConfigureVideo (driver, flags, width, height,
togglefullscreen);
#else
driver = TFB_GFXDRIVER_SDL_PURE;
log_add (log_Warning, "OpenGL support not compiled in,"
" so using pure SDL driver");
result = TFB_Pure_ConfigureVideo (driver, flags, width, height,
togglefullscreen);
#endif
}
else
{
result = TFB_Pure_ConfigureVideo (driver, flags, width, height,
togglefullscreen);
}
sprintf (caption, "The Ur-Quan Masters v%d.%d.%d%s",
UQM_MAJOR_VERSION, UQM_MINOR_VERSION,
UQM_PATCH_VERSION, UQM_EXTRA_VERSION);
SDL_WM_SetCaption (caption, NULL);
if (flags & TFB_GFXFLAGS_FULLSCREEN)
SDL_ShowCursor (SDL_DISABLE);
else
SDL_ShowCursor (SDL_ENABLE);
return result;
}
int
TFB_InitGraphics (int driver, int flags, int width, int height)
{
int result, i;
int result;
char caption[200];
/* Null out screen pointers the first time */
for (i = 0; i < TFB_GFX_NUMSCREENS; i++)
{
SDL_Screens[i] = NULL;
}
GfxFlags = flags;
if (driver == TFB_GFXDRIVER_SDL_OPENGL)
@@ -95,17 +173,25 @@ TFB_InitGraphics (int driver, int flags, int width, int height)
TFB_DrawCanvas_Initialize ();
atexit (TFB_UninitGraphics);
return 0;
}
void
TFB_UninitGraphics (void)
{
int i;
Uninit_DrawCommandQueue ();
// TODO: Uninit whatever the drivers have set up for us
SDL_Quit ();
for (i = 0; i < TFB_GFX_NUMSCREENS; i++)
UnInit_Screen (&SDL_Screens[i]);
TFB_Pure_UninitGraphics ();
#ifdef HAVE_OPENGL
TFB_GL_UninitGraphics ();
#endif
UnInit_Screen (&format_conv_surf);
}
void
@@ -113,7 +199,7 @@ TFB_ProcessEvents ()
{
SDL_Event Event;
while (SDL_PollEvent (&Event))
while (SDL_PollEvent (&Event) > 0)
{
/* Run through the InputEvent filter. */
ProcessInputEvent (&Event);
+4
View File
@@ -55,4 +55,8 @@ int TFB_SetColorKey (SDL_Surface *surface, Uint32 key, int rleaccel);
int TFB_DisableColorKey (SDL_Surface *surface);
int TFB_SetColors (SDL_Surface *surface, SDL_Color *colors, int firstcolor, int ncolors);
SDL_Surface* Create_Screen (SDL_Surface *templat, int w, int h);
int ReInit_Screen (SDL_Surface **screen, SDL_Surface *templat, int w, int h);
void UnInit_Screen (SDL_Surface **screen);
#endif
+10 -1
View File
@@ -301,6 +301,7 @@ TFB_DrawImage_New (TFB_Canvas canvas)
img->last_scale_hs = NullHs;
img->last_scale_type = -1;
img->last_scale = 0;
img->dirty = FALSE;
TFB_DrawCanvas_GetExtent (canvas, &img->extent);
if (TFB_DrawCanvas_IsPaletted (canvas))
@@ -414,8 +415,16 @@ TFB_DrawImage_Delete (TFB_Image *image)
TFB_DrawCanvas_Delete (image->NormalImg);
if (image->ScaledImg) {
if (image->ScaledImg)
{
TFB_DrawCanvas_Delete (image->ScaledImg);
image->ScaledImg = 0;
}
if (image->FilledImg)
{
TFB_DrawCanvas_Delete (image->FilledImg);
image->FilledImg = 0;
}
UnlockMutex (image->mutex);
+2 -2
View File
@@ -131,7 +131,7 @@ TFB_Prim_Stamp (STAMP *stmp, DrawMode mode, POINT ctxOrigin)
if (!SrcFramePtr)
{
log_add (log_Warning, "TFB_Prim_Stamp: Tried to draw a NULL frame"
" (Stamp address = %p)", stmp);
" (Stamp address = %p)", (void *) stmp);
return;
}
img = SrcFramePtr->image;
@@ -180,7 +180,7 @@ TFB_Prim_StampFill (STAMP *stmp, Color color, DrawMode mode, POINT ctxOrigin)
if (!SrcFramePtr)
{
log_add (log_Warning, "TFB_Prim_StampFill: Tried to draw a NULL frame"
" (Stamp address = %p)", stmp);
" (Stamp address = %p)", (void *) stmp);
return;
}
img = SrcFramePtr->image;
+7
View File
@@ -1,2 +1,9 @@
#if defined(__cplusplus)
extern "C" {
#endif
#include "heap/heap.h"
#if defined(__cplusplus)
}
#endif
+1 -1
View File
@@ -1,2 +1,2 @@
uqm_CFILES="heap.c"
uqm_HFILES="heap.h"
+1 -1
View File
@@ -49,7 +49,7 @@ Heap_new(HeapValue_Comparator comparator, size_t initialSize, size_t minSize,
heap->minSize = minSize;
heap->minFillQuotient = minFillQuotient;
heap->size = nextPower2(initialSize);
heap->minFill = (size_t) ceil(((double) (heap->size >> 1))
heap->minFill = ceil(((double) (heap->size >> 1))
* heap->minFillQuotient);
heap->entries = malloc(heap->size * sizeof (HeapValue *));
heap->numEntries = 0;
+11 -4
View File
@@ -24,6 +24,10 @@
#include "libs/uio.h"
#include "libs/unicode.h"
#if defined(__cplusplus)
extern "C" {
#endif
extern BOOLEAN AnyButtonPress (BOOLEAN DetectSpecial);
@@ -49,9 +53,9 @@ UniChar GetLastCharacter (void);
/* Interrogating the current key configuration */
void InterrogateInputState (int template, int control, int index, char *buffer, int maxlen);
void RemoveInputState (int template, int control, int index);
void RebindInputState (int template, int control, int index);
void InterrogateInputState (int templat, int control, int index, char *buffer, int maxlen);
void RemoveInputState (int templat, int control, int index);
void RebindInputState (int templat, int control, int index);
void SaveKeyConfiguration (uio_DirHandle *path, const char *fname);
@@ -59,5 +63,8 @@ void SaveKeyConfiguration (uio_DirHandle *path, const char *fname);
void BeginInputFrame (void);
#endif /* LIBS_INPLIB_H_ */
#if defined(__cplusplus)
}
#endif
#endif /* LIBS_INPLIB_H */
+1
View File
@@ -3,3 +3,4 @@ if [ "$uqm_GFXMODULE" = "sdl" ]; then
fi
uqm_CFILES="input_common.c"
uqm_HFILES="inpintrn.h input_common.h"
+1
View File
@@ -1 +1,2 @@
uqm_CFILES="input.c keynames.c vcontrol.c"
uqm_HFILES="input.h keynames.h vcontrol.h"
+45 -24
View File
@@ -18,8 +18,10 @@
#include <assert.h>
#include <errno.h>
#include <string.h>
#include "input.h"
#include "../inpintrn.h"
#include "libs/graphics/sdl/sdl_common.h"
#include "libs/threadlib.h"
#include "libs/input/sdl/vcontrol.h"
#include "libs/input/sdl/keynames.h"
#include "libs/memlib.h"
@@ -218,13 +220,12 @@ TFB_SetInputVectors (volatile int menu[], int num_menu_, volatile int flight[],
num_flight = num_flight_;
}
int
TFB_InitInput (int driver, int flags)
#ifdef HAVE_JOYSTICK
static void
initJoystick (void)
{
int i;
int nJoysticks;
(void)driver;
(void)flags;
#if SDL_MAJOR_VERSION == 1
SDL_EnableUNICODE(1);
@@ -246,6 +247,8 @@ TFB_InitInput (int driver, int flags)
nJoysticks = SDL_NumJoysticks ();
if (nJoysticks > 0)
{
int i;
log_add (log_Info, "The names of the joysticks are:");
for (i = 0; i < nJoysticks; i++)
{
@@ -258,6 +261,23 @@ TFB_InitInput (int driver, int flags)
}
SDL_JoystickEventState (SDL_ENABLE);
}
}
#endif /* HAVE_JOYSTICK */
int
TFB_InitInput (int driver, int flags)
{
(void)driver;
(void)flags;
SDL_EnableUNICODE(1);
(void)SDL_GetKeyState (&num_keys);
kbdstate = (int *)HMalloc (sizeof (int) * (num_keys + 1));
#ifdef HAVE_JOYSTICK
initJoystick ();
#endif /* HAVE_JOYSTICK */
in_character_mode = FALSE;
@@ -271,7 +291,6 @@ TFB_InitInput (int driver, int flags)
VControl_ResetInput ();
InputInitialized = TRUE;
atexit (TFB_UninitInput);
return 0;
}
@@ -328,7 +347,7 @@ GetLastCharacter (void)
volatile int MouseButtonDown = 0;
void
static void
ProcessMouseEvent (const SDL_Event *e)
{
switch (e->type)
@@ -372,10 +391,12 @@ ProcessInputEvent (const SDL_Event *Event)
if (Event->type == SDL_KEYDOWN || Event->type == SDL_KEYUP)
{ // process character input event, if any
SDLKey k = Event->key.keysym.sym;
// keysym.sym is an SDLKey type which is an enum and can be signed
// or unsigned on different platforms; we'll use a guaranteed type
int k = Event->key.keysym.sym;
UniChar map_key = Event->key.keysym.unicode;
if (k > num_keys)
if (k < 0 || k > num_keys)
k = num_keys; // for unknown keys
if (Event->type == SDL_KEYDOWN)
@@ -494,11 +515,11 @@ TFB_ResetControls (void)
}
void
InterrogateInputState (int template, int control, int index, char *buffer, int maxlen)
InterrogateInputState (int templat, int control, int index, char *buffer, int maxlen)
{
VCONTROL_GESTURE *g = CONTROL_PTR(template, control, index);
VCONTROL_GESTURE *g = CONTROL_PTR(templat, control, index);
if (template >= num_templ || control >= num_flight
if (templat >= num_templ || control >= num_flight
|| index >= MAX_FLIGHT_ALTERNATES)
{
log_add (log_Warning, "InterrogateInputState(): invalid control index");
@@ -531,13 +552,13 @@ InterrogateInputState (int template, int control, int index, char *buffer, int m
}
void
RemoveInputState (int template, int control, int index)
RemoveInputState (int templat, int control, int index)
{
VCONTROL_GESTURE *g = CONTROL_PTR(template, control, index);
VCONTROL_GESTURE *g = CONTROL_PTR(templat, control, index);
char keybuf[40];
keybuf[39] = '\0';
if (template >= num_templ || control >= num_flight
if (templat >= num_templ || control >= num_flight
|| index >= MAX_FLIGHT_ALTERNATES)
{
log_add (log_Warning, "RemoveInputState(): invalid control index");
@@ -545,23 +566,23 @@ RemoveInputState (int template, int control, int index)
}
VControl_RemoveGestureBinding (g,
(int *)(flight_vec + template * num_flight + control));
(int *)(flight_vec + templat * num_flight + control));
g->type = VCONTROL_NONE;
snprintf (keybuf, 39, "keys.%d.%s.%d", template+1, flight_res_names[control], index+1);
snprintf (keybuf, 39, "keys.%d.%s.%d", templat+1, flight_res_names[control], index+1);
res_Remove (keybuf);
return;
}
void
RebindInputState (int template, int control, int index)
RebindInputState (int templat, int control, int index)
{
VCONTROL_GESTURE g;
char keybuf[40], valbuf[40];
keybuf[39] = valbuf[39] = '\0';
if (template >= num_templ || control >= num_flight
if (templat >= num_templ || control >= num_flight
|| index >= MAX_FLIGHT_ALTERNATES)
{
log_add (log_Warning, "RebindInputState(): invalid control index");
@@ -569,7 +590,7 @@ RebindInputState (int template, int control, int index)
}
/* Remove the old binding on this spot */
RemoveInputState (template, control, index);
RemoveInputState (templat, control, index);
/* Wait for the next interesting bit of user input */
VControl_ClearGesture ();
@@ -580,9 +601,9 @@ RebindInputState (int template, int control, int index)
/* And now, add the new binding. */
VControl_AddGestureBinding (&g,
(int *)(flight_vec + template * num_flight + control));
*CONTROL_PTR(template, control, index) = g;
snprintf (keybuf, 39, "keys.%d.%s.%d", template+1, flight_res_names[control], index+1);
(int *)(flight_vec + templat * num_flight + control));
*CONTROL_PTR(templat, control, index) = g;
snprintf (keybuf, 39, "keys.%d.%s.%d", templat+1, flight_res_names[control], index+1);
VControl_DumpGesture (valbuf, 39, &g);
res_PutString (keybuf, valbuf);
}
+3
View File
@@ -19,6 +19,9 @@
#ifndef INPUT_H
#define INPUT_H
#include "port.h"
#include SDL_INCLUDE(SDL.h)
extern void ProcessInputEvent (const SDL_Event *Event);
#endif
+4 -4
View File
@@ -33,7 +33,7 @@
* tragedy. */
typedef struct vcontrol_keyname {
/* const */ char *name;
const char *name;
int code;
} keyname;
@@ -197,7 +197,7 @@ static keyname keynames[] = {
{"Unknown", 0}};
/* Last element must have code zero */
char *
const char *
VControl_code2name (int code)
{
int i = 0;
@@ -213,12 +213,12 @@ VControl_code2name (int code)
}
int
VControl_name2code (char *name)
VControl_name2code (const char *name)
{
int i = 0;
while (1)
{
char *test = keynames[i].name;
const char *test = keynames[i].name;
int code = keynames[i].code;
if (!strcasecmp(test, name) || !code)
{
+2 -2
View File
@@ -17,6 +17,6 @@
#ifndef LIBS_INPUT_SDL_KEYNAMES_H_
#define LIBS_INPUT_SDL_KEYNAMES_H_
char *VControl_code2name (int code);
int VControl_name2code (char *code);
const char *VControl_code2name (int code);
int VControl_name2code (const char *code);
#endif
+2 -1
View File
@@ -195,6 +195,7 @@ static void
key_init (void)
{
unsigned int i;
int num_keys; // Temp to match type of param for SDL_GetKeyState().
pool = allocate_key_chunk ();
for (i = 0; i < KEYBOARD_INPUT_BUCKETS; i++)
bindings[i] = NULL;
@@ -1265,7 +1266,7 @@ VControl_ParseGesture (VCONTROL_GESTURE *g, const char *spec)
parse_state ps;
strncpy (ps.line, spec, LINE_SIZE);
ps.line[LINE_SIZE] = '\0';
ps.line[LINE_SIZE - 1] = '\0';
ps.index = ps.error = 0;
ps.linenum = -1;
+9
View File
@@ -16,5 +16,14 @@
*
*/
#if defined(__cplusplus)
extern "C" {
#endif
#include "list/list.h"
#if defined(__cplusplus)
}
#endif
+1
View File
@@ -1 +1,2 @@
uqm_CFILES="list.c"
uqm_HFILES="list.h"
+8
View File
@@ -14,4 +14,12 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#if defined(__cplusplus)
extern "C" {
#endif
#include "log/uqmlog.h"
#if defined(__cplusplus)
}
#endif
+2
View File
@@ -1,4 +1,5 @@
uqm_CFILES="uqmlog.c"
uqm_HFILES="loginternal.h msgbox.h uqmlog.h"
case "$HOST_SYSTEM" in
Darwin)
@@ -11,3 +12,4 @@ case "$HOST_SYSTEM" in
uqm_CFILES="$uqm_CFILES msgbox_stub.c"
;;
esac
+1
View File
@@ -159,6 +159,7 @@ log_exit (int code)
{
qlock = 0;
DestroyMutex (qmutex);
qmutex = 0;
}
return code;
+1
View File
@@ -1 +1,2 @@
uqm_CFILES="random.c random2.c sqrt.c"
uqm_HFILES="mthintrn.h random.h"
+1 -7
View File
@@ -29,13 +29,6 @@
#ifndef LIBS_MATH_RANDOM_H_
#define LIBS_MATH_RANDOM_H_
/* ----------------------------DEFINES------------------------------------ */
#define RAND(n) ( (int) ( (unsigned int)TFB_Random() % (n) ) )
#define SRAND(n) ( (int)TFB_Random() % (n) )
#define AND_RAND(n) ( (int)TFB_Random() & (n) )
/* ----------------------------GLOBALS/EXTERNS---------------------------- */
DWORD TFB_SeedRandom (DWORD seed);
@@ -55,6 +48,7 @@ void RandomContext_Delete (RandomContext *context);
RandomContext *RandomContext_Copy (const RandomContext *source);
DWORD RandomContext_Random (RandomContext *context);
DWORD RandomContext_SeedRandom (RandomContext *context, DWORD new_seed);
DWORD RandomContext_GetSeed (RandomContext *context);
#endif /* LIBS_MATH_RANDOM_H_ */
+5 -1
View File
@@ -82,4 +82,8 @@ RandomContext_SeedRandom (RandomContext *context, DWORD new_seed)
return old_seed;
}
DWORD
RandomContext_GetSeed (RandomContext *context)
{
return context->seed;
}
+9 -2
View File
@@ -20,10 +20,17 @@
#define LIBS_MATHLIB_H_
#include "libs/compiler.h"
#if defined(__cplusplus)
extern "C" {
#endif
#include "math/random.h"
extern COUNT square_root (DWORD value);
#if defined(__cplusplus)
}
#endif
#endif /* LIBS_MATHLIB_H_ */
+8 -1
View File
@@ -19,7 +19,14 @@
#ifndef LIBS_MD5_H_
#define LIBS_MD5_H_
#if defined(__cplusplus)
extern "C" {
#endif
#include "md5/md5.h"
#endif /* LIBS_MD5_H_ */
#if defined(__cplusplus)
}
#endif
#endif /* LIBS_MD5_H_ */
+1 -1
View File
@@ -1,2 +1,2 @@
uqm_CFILES="md5.c"
uqm_HFILES="md5.h"
+13 -3
View File
@@ -19,15 +19,25 @@
#ifndef LIBS_MEMLIB_H_
#define LIBS_MEMLIB_H_
#include <stddef.h>
#include "types.h"
#if defined(__cplusplus)
extern "C" {
#endif
extern bool mem_init (void);
extern bool mem_uninit (void);
extern void *HMalloc (int size);
extern void *HMalloc (size_t size);
extern void HFree (void *p);
extern void *HCalloc (int size);
extern void *HRealloc (void *p, int size);
extern void *HCalloc (size_t size);
extern void *HRealloc (void *p, size_t size);
#if defined(__cplusplus)
}
#endif
#endif /* LIBS_MEMLIB_H_ */
+12 -33
View File
@@ -38,68 +38,47 @@ mem_uninit (void)
}
void *
HMalloc (int size)
HMalloc (size_t size)
{
void *p;
if (size == 0)
return NULL;
if (size < 0)
{
log_add (log_Fatal, "HMalloc() FATAL: "
"request for negative amount of memory %d!", size);
fflush (stderr);
explode ();
}
p = malloc (size);
if (p == NULL)
void *p = malloc (size);
if (p == NULL && size > 0)
{
log_add (log_Fatal, "HMalloc() FATAL: out of memory.");
fflush (stderr);
explode ();
}
return (p);
return p;
}
void
HFree (void *p)
{
if (p)
{
free (p);
}
free (p);
}
void *
HCalloc (int size)
HCalloc (size_t size)
{
void *p;
p = HMalloc (size);
memset (p, 0, size);
return (p);
return p;
}
void *
HRealloc (void *p, int size)
HRealloc (void *p, size_t size)
{
if (size < 0)
{
log_add (log_Fatal, "HRealloc() FATAL: "
"request for negative amount of memory %d!", size);
fflush (stderr);
explode ();
}
p = realloc (p, size);
if (!p && size > 0)
if (p == NULL && size > 0)
{
log_add (log_Fatal, "HRealloc() FATAL: out of memory.");
fflush (stderr);
explode ();
}
return p;
}
+1
View File
@@ -2,3 +2,4 @@ uqm_CFILES="drv_nos.c load_it.c load_mod.c load_s3m.c load_stm.c load_xm.c
mdreg.c mdriver.c mloader.c
mlreg.c mlutil.c mmalloc.c mmerror.c mmio.c mplayer.c munitrk.c
mwav.c npertab.c sloader.c virtch.c virtch2.c virtch_common.c"
uqm_HFILES="mikmod_build.h mikmod.h mikmod_internals.h"
+10 -2
View File
@@ -26,6 +26,10 @@
#include <stdlib.h>
#include "port.h"
#if defined(__cplusplus)
extern "C" {
#endif
extern int TFB_DEBUG_HALT;
@@ -47,12 +51,16 @@ static inline void explode (void)
static inline void *
unconst(const void *arg) {
union {
char *c;
const char *cc;
void *c;
const void *cc;
} u;
u.cc = arg;
return u.c;
}
#if defined(__cplusplus)
}
#endif
#endif
+8 -1
View File
@@ -19,11 +19,18 @@
#ifndef LIBS_NET_H_
#define LIBS_NET_H_
#if defined(__cplusplus)
extern "C" {
#endif
#include "network/network.h"
#include "network/netmanager/netmanager.h"
#include "network/connect/connect.h"
#include "network/connect/listen.h"
#include "network/connect/resolve.h"
#endif /* LIBS_NET_H_ */
#if defined(__cplusplus)
}
#endif
#endif /* LIBS_NET_H_ */
+3
View File
@@ -1,9 +1,12 @@
uqm_SUBDIRS="connect netmanager socket"
uqm_CFILES="netport.c"
uqm_HFILES="bytesex.h netport.h network.h"
if [ -n "$uqm_USE_WINSOCK" ]; then
uqm_CFILES="$uqm_CFILES network_win.c"
if [ -n "$MACRO___MINGW32__" ]; then
uqm_CFILES="$uqm_CFILES wspiapiwrap.c"
uqm_HFILES="$uqm_HFILES wspiapiwrap.h"
fi
else
uqm_CFILES="$uqm_CFILES network_bsd.c"
+1 -1
View File
@@ -1,2 +1,2 @@
uqm_CFILES="connect.c listen.c resolve.c"
uqm_HFILES="connect.h listen.h resolve.h"
+1 -1
View File
@@ -57,7 +57,7 @@ static void doConnectErrorCallback(ConnectState *connectState,
static ConnectState *
ConnectState_alloc(void) {
return (ConnectState *) malloc(sizeof (ConnectState));
};
}
static void
ConnectState_free(ConnectState *connectState) {
+1 -1
View File
@@ -56,7 +56,7 @@ static void doListenErrorCallback(ListenState *listenState,
static ListenState *
ListenState_alloc(void) {
return (ListenState *) malloc(sizeof (ListenState));
};
}
static void
ListenState_free(ListenState *listenState) {
+1 -1
View File
@@ -33,7 +33,7 @@
static ResolveState *
ResolveState_new(void) {
return (ResolveState *) malloc(sizeof (ResolveState));
};
}
static void
ResolveState_free(ResolveState *resolveState) {
+4 -1
View File
@@ -1,8 +1,11 @@
uqm_CFILES="ndesc.c"
uqm_HFILES="ndesc.h netmanager.h"
if [ -n "$uqm_USE_WINSOCK" ]; then
uqm_CFILES="$uqm_CFILES netmanager_win.c"
uqm_HFILES="$uqm_HFILES netmanager_win.h"
else
uqm_CFILES="$uqm_CFILES netmanager_bsd.c"
uqm_HFILES="$uqm_HFILES netmanager_bsd.h"
fi
+4
View File
@@ -1,7 +1,11 @@
uqm_CFILES="socket.c"
uqm_HFILES="socket.h"
if [ -n "$uqm_USE_WINSOCK" ]; then
uqm_CFILES="$uqm_CFILES socket_win.c"
uqm_HFILES="$uqm_HFILES socket_win.h"
else
uqm_CFILES="$uqm_CFILES socket_bsd.c"
uqm_HFILES="$uqm_CFILES socket_bsd.h"
fi
+4
View File
@@ -80,7 +80,11 @@ int Socket_bind(Socket *sock, const struct sockaddr *addr,
int Socket_listen(Socket *sock, int backlog);
Socket *Socket_accept(Socket *sock, struct sockaddr *addr, socklen_t *addrLen);
ssize_t Socket_send(Socket *sock, const void *buf, size_t len, int flags);
ssize_t Socket_sendto(Socket *sock, const void *buf, size_t len, int flags,
const struct sockaddr *addr, socklen_t addrLen);
ssize_t Socket_recv(Socket *sock, void *buf, size_t len, int flags);
ssize_t Socket_recvfrom(Socket *sock, void *buf, size_t len, int flags,
struct sockaddr *from, socklen_t *fromLen);
int Socket_setNonBlocking(Socket *sock);
int Socket_setReuseAddr(Socket *sock);
+12
View File
@@ -129,11 +129,23 @@ Socket_send(Socket *sock, const void *buf, size_t len, int flags) {
return send(sock->fd, buf, len, flags);
}
ssize_t
Socket_sendto(Socket *sock, const void *buf, size_t len, int flags,
const struct sockaddr *addr, socklen_t addrLen) {
return sendto(sock->fd, buf, len, flags, addr, addrLen);
}
ssize_t
Socket_recv(Socket *sock, void *buf, size_t len, int flags) {
return recv(sock->fd, buf, len, flags);
}
ssize_t
Socket_recvfrom(Socket *sock, void *buf, size_t len, int flags,
struct sockaddr *from, socklen_t *fromLen) {
return recvfrom(sock->fd, buf, len, flags, from, fromLen);
}
int
Socket_setNonBlocking(Socket *sock) {
int flags;
+28
View File
@@ -159,6 +159,20 @@ Socket_send(Socket *sock, const void *buf, size_t len, int flags) {
return sendResult;
}
ssize_t
Socket_sendto(Socket *sock, const void *buf, size_t len, int flags,
const struct sockaddr *addr, socklen_t addrLen) {
int sendResult;
sendResult = sendto(sock->sock, buf, len, flags, addr, addrLen);
if (sendResult == SOCKET_ERROR) {
errno = getWinsockErrno();
return -1;
}
return sendResult;
}
ssize_t
Socket_recv(Socket *sock, void *buf, size_t len, int flags) {
int recvResult;
@@ -172,6 +186,20 @@ Socket_recv(Socket *sock, void *buf, size_t len, int flags) {
return recvResult;
}
ssize_t
Socket_recvfrom(Socket *sock, void *buf, size_t len, int flags,
struct sockaddr *from, socklen_t *fromLen) {
int recvResult;
recvResult = recvfrom(sock->sock, buf, len, flags, from, fromLen);
if (recvResult == SOCKET_ERROR) {
errno = getWinsockErrno();
return -1;
}
return recvResult;
}
int
Socket_setNonBlocking(Socket *sock) {
unsigned long flag = 1;
+8
View File
@@ -17,6 +17,10 @@
#ifndef PLATFORM_H_
#define PLATFORM_H_
#if defined(__cplusplus)
extern "C" {
#endif
#if defined(USE_PLATFORM_ACCEL)
# if defined(__GNUC__) && (defined(i386) || defined(__x86_64__))
# define MMX_ASM
@@ -46,4 +50,8 @@ typedef enum
extern PLATFORM_TYPE force_platform;
#if defined(__cplusplus)
}
#endif
#endif /* PLATFORM_H_ */
+17
View File
@@ -25,6 +25,10 @@
#include "libs/memlib.h"
#include "libs/uio.h"
#if defined(__cplusplus)
extern "C" {
#endif
typedef struct resource_index_desc RESOURCE_INDEX_DESC;
typedef RESOURCE_INDEX_DESC *RESOURCE_INDEX;
@@ -33,6 +37,7 @@ typedef const char *RESOURCE;
typedef union {
DWORD num;
void *ptr;
const char *str;
} RESOURCE_DATA;
#define NULL_RESOURCE NULL
@@ -78,8 +83,16 @@ void *GetResourceData (uio_Stream *fp, DWORD length);
#define AllocResourceData HMalloc
BOOLEAN FreeResourceData (void *);
#if defined(__cplusplus)
}
#endif
#include "libs/strlib.h"
#include "libs/gfxlib.h"
#if defined(__cplusplus)
extern "C" {
#endif
// For Color
typedef STRING_TABLE DIRENTRY_REF;
@@ -120,4 +133,8 @@ void res_PutColor (const char *key, Color value);
BOOLEAN res_Remove (const char *key);
#if defined(__cplusplus)
}
#endif
#endif /* LIBS_RESLIB_H_ */
+1
View File
@@ -1,2 +1,3 @@
uqm_CFILES="direct.c filecntl.c getres.c loadres.c stringbank.c
propfile.c resinit.c"
uqm_HFILES="index.h propfile.h resintrn.h stringbank.h"
+7 -4
View File
@@ -19,19 +19,22 @@
#ifndef LIBS_RESOURCE_INDEX_H_
#define LIBS_RESOURCE_INDEX_H_
typedef struct resource_handlers ResourceHandlers;
typedef struct resource_desc ResourceDesc;
#include <stdio.h>
#include "libs/reslib.h"
#include "libs/uio/charhashtable.h"
typedef struct resource_handlers
struct resource_handlers
{
const char *resType;
ResourceLoadFun *loadFun;
ResourceFreeFun *freeFun;
ResourceStringFun *toString;
} ResourceHandlers;
};
typedef struct resource_desc
struct resource_desc
{
RESOURCE res_id;
char *fname;
@@ -39,7 +42,7 @@ typedef struct resource_desc
RESOURCE_DATA resdata;
// refcount is rudimentary as nothing really frees the descriptors
unsigned refcount;
} ResourceDesc;
};
struct resource_index_desc
{
+10 -9
View File
@@ -34,7 +34,8 @@
static RESOURCE_INDEX
allocResourceIndex (void) {
RESOURCE_INDEX ndx = HMalloc (sizeof (RESOURCE_INDEX_DESC));
ndx->map = CharHashTable_newHashTable (NULL, NULL, NULL, NULL, 0, 0.85, 0.9);
ndx->map = CharHashTable_newHashTable (NULL, NULL, NULL, NULL, NULL,
0, 0.85, 0.9);
return ndx;
}
@@ -138,7 +139,7 @@ process_resource_desc (const char *key, const char *value)
static void
UseDescriptorAsRes (const char *descriptor, RESOURCE_DATA *resdata)
{
resdata->ptr = (void *)descriptor;
resdata->str = descriptor;
}
static void
@@ -285,7 +286,7 @@ fail:
static void
RawDescriptor (RESOURCE_DATA *resdata, char *buf, unsigned int size)
{
snprintf (buf, size, "%s", (char *)resdata->ptr);
snprintf (buf, size, "%s", resdata->str);
}
static void
@@ -474,12 +475,12 @@ res_GetString (const char *key)
{
RESOURCE_INDEX idx = _get_current_index_header ();
ResourceDesc *desc = lookupResourceDesc (idx, key);
if (!desc || !desc->resdata.ptr || strcmp(desc->vtable->resType, "STRING"))
if (!desc || !desc->resdata.str || strcmp(desc->vtable->resType, "STRING"))
return "";
/* TODO: Work out exact STRING semantics, specifically, the lifetime of
* the returned value. If caller is allowed to reference the returned
* value forever, STRING has to be ref-counted. */
return (const char *)desc->resdata.ptr;
return desc->resdata.str;
}
void
@@ -488,24 +489,24 @@ res_PutString (const char *key, const char *value)
RESOURCE_INDEX idx = _get_current_index_header ();
ResourceDesc *desc = lookupResourceDesc (idx, key);
int srclen, dstlen;
if (!desc || !desc->resdata.ptr || strcmp(desc->vtable->resType, "STRING"))
if (!desc || !desc->resdata.str || strcmp(desc->vtable->resType, "STRING"))
{
/* TODO: This is kind of roundabout. We can do better by refactoring newResourceDesc */
process_resource_desc(key, "STRING:undefined");
desc = lookupResourceDesc (idx, key);
}
srclen = strlen (value);
dstlen = strlen (desc->resdata.ptr);
dstlen = strlen (desc->fname);
if (srclen > dstlen) {
char *newValue = HMalloc(srclen + 1);
char *oldValue = desc->fname;
log_add(log_Warning, "Reallocating string space for '%s'", key);
strncpy (newValue, value, srclen + 1);
desc->resdata.ptr = newValue;
desc->resdata.str = newValue;
desc->fname = newValue;
HFree (oldValue);
} else {
strncpy (desc->resdata.ptr, value, srclen + 1);
strncpy (desc->fname, value, srclen + 1);
}
}
+8
View File
@@ -22,6 +22,10 @@
#include "port.h"
#include "libs/strlib.h"
#if defined(__cplusplus)
extern "C" {
#endif
typedef STRING_TABLE SOUND_REF;
typedef STRING SOUND;
// SOUNDPTR is really a TFB_SoundSample**
@@ -95,5 +99,9 @@ extern void WaitForSoundEnd (COUNT Channel);
extern DWORD FadeMusic (BYTE end_vol, SIZE TimeInterval);
#if defined(__cplusplus)
}
#endif
#endif /* LIBS_SNDLIB_H_ */
+1 -1
View File
@@ -6,4 +6,4 @@ else
fi
uqm_CFILES="audiocore.c fileinst.c resinst.c sound.c sfx.c music.c stream.c trackplayer.c"
uqm_HFILES="audiocore.h sndintrn.h sound.h stream.h trackint.h trackplayer.h"
+5
View File
@@ -20,6 +20,7 @@
#include <stdio.h>
#include <stdlib.h>
#include "audiocore.h"
#include "sound.h"
#include "libs/log.h"
static audio_Driver audiodrv;
@@ -76,6 +77,10 @@ initAudio (sint32 driver, sint32 flags)
"NOTICE: Try running UQM with '--sound=none' option");
exit (EXIT_FAILURE);
}
SetSFXVolume (sfxVolumeScale);
SetSpeechVolume (speechVolumeScale);
SetMusicVolume (musicVolume);
audio_inited = true;
+2
View File
@@ -1,6 +1,8 @@
uqm_CFILES="decoder.c aiffaud.c wav.c dukaud.c modaud.c"
uqm_HFILES="aiffaud.h decoder.h dukaud.h modaud.h wav.h"
if [ "$uqm_OGGVORBIS" '!=' "none" ]; then
uqm_CFILES="$uqm_CFILES oggaud.c"
uqm_HFILES="$uqm_HFILES oggaud.h"
fi
+3 -3
View File
@@ -307,7 +307,7 @@ aifa_readCommonChunk (TFB_AiffSoundDecoder* aifa, uint32 size,
{
int bytes;
memset(fmt, sizeof(*fmt), 0);
memset(fmt, 0, sizeof(*fmt));
if (size < AIFF_COMM_SIZE)
{
aifa->last_error = aifae_BadFile;
@@ -369,7 +369,7 @@ aifa_Open (THIS_PTR, uio_DirHandle *dir, const char *filename)
aifa->max_pcm = 0;
aifa->data_ofs = 0;
memset(&aifa->fmtHdr, 0, sizeof(aifa->fmtHdr));
memset(aifa->prev_val, sizeof(aifa->prev_val), 0);
memset(aifa->prev_val, 0, sizeof(aifa->prev_val));
// read wave header
if (!aifa_readFileHeader (aifa, &fileHdr))
@@ -635,7 +635,7 @@ aifa_Seek (THIS_PTR, uint32 pcm_pos)
// reset previous values for SDX2 on seek ops
// the delta will recover faster with reset
memset(aifa->prev_val, sizeof(aifa->prev_val), 0);
memset(aifa->prev_val, 0, sizeof(aifa->prev_val));
return pcm_pos;
}
+3 -3
View File
@@ -105,7 +105,7 @@ typedef struct
static const TFB_DecoderFormats* duka_formats = NULL;
sint32
static sint32
duka_readAudFrameHeader (TFB_DuckSoundDecoder* duka, uint32 iframe,
DukAud_AudSubframe* aud)
{
@@ -246,7 +246,7 @@ decode_nibbles (sint16 *output, sint32 output_size, sint32 channels,
}
// *** END part copied from MPlayer ***
sint32
static sint32
duka_decodeFrame (TFB_DuckSoundDecoder* duka, DukAud_AudSubframe* header,
uint8* input)
{
@@ -273,7 +273,7 @@ duka_decodeFrame (TFB_DuckSoundDecoder* duka, DukAud_AudSubframe* header,
}
sint32
static sint32
duka_readNextFrame (TFB_DuckSoundDecoder* duka)
{
DukAud_FrameHeader hdr;
+15 -9
View File
@@ -88,7 +88,7 @@ static void* buffer;
static ULONG bufsize;
static ULONG written;
ULONG*
static ULONG*
moda_mmout_SetOutputBuffer (void* buf, ULONG size)
{
buffer = buf;
@@ -132,12 +132,18 @@ moda_mmout_Reset (void)
return 0;
}
static char MDRIVER_name[] = "Mem Buffer";
static char MDRIVER_version[] = "Mem Buffer driver v1.1";
static char MDRIVER_alias[] = "membuf";
static MDRIVER moda_mmout_drv =
{ NULL,
"Mem Buffer", // Name
"Mem Buffer driver v1.1", // Version
0, 255, // Voice limits
"membuf", // Alias
{
NULL,
//xxx libmikmod does not declare these fields const; it probably should.
MDRIVER_name, // Name
MDRIVER_version, // Version
0, 255, // Voice limits
MDRIVER_alias, // Alias
// The minimum mikmod version we support is 3.1.8
#if (LIBMIKMOD_VERSION_MAJOR > 3) || \
@@ -215,7 +221,7 @@ moda_uioReader_Tell (MREADER* reader)
return uio_ftell (((MUIOREADER*)reader)->file);
}
MREADER*
static MREADER*
moda_new_uioReader (uio_Stream* fp)
{
MUIOREADER* reader = (MUIOREADER*) HMalloc (sizeof(MUIOREADER));
@@ -231,7 +237,7 @@ moda_new_uioReader (uio_Stream* fp)
return (MREADER*)reader;
}
void
static void
moda_delete_uioReader (MREADER* reader)
{
if (reader)
@@ -276,7 +282,7 @@ moda_InitModule (int flags, const TFB_DecoderFormats* fmts)
md_pansep = 64;
if (MikMod_Init (""))
if (MikMod_Init (NULL))
{
log_add (log_Error, "MikMod_Init() failed, %s",
MikMod_strerror (MikMod_errno));
+1
View File
@@ -1,2 +1,3 @@
uqm_SUBDIRS="sdl nosound"
uqm_CFILES="mixer.c"
uqm_HFILES="mixer.h mixerint.h"
+8 -8
View File
@@ -1569,7 +1569,7 @@ mixer_ResampleNone (mixer_Source *src, bool left)
uint8 *d0 = src->nextqueued->data + src->pos;
src->pos += mixer_chansize;
(void) left; // satisfying compiler - unused arg
return (float)mixer_GetSampleInt (d0, mixer_chansize);
return mixer_GetSampleInt (d0, mixer_chansize);
}
/* get a resampled (up/down) sample from source (nearest neighbor) */
@@ -1578,7 +1578,7 @@ mixer_ResampleNearest (mixer_Source *src, bool left)
{
uint8 *d0 = src->nextqueued->data + src->pos;
d0 += mixer_SourceAdvance (src, left);
return (float)mixer_GetSampleInt (d0, mixer_chansize);
return mixer_GetSampleInt (d0, mixer_chansize);
}
/* get an upsampled sample from source (linear interpolation) */
@@ -1608,8 +1608,8 @@ mixer_UpsampleLinear (mixer_Source *src, bool left)
else
d1 = d0 + curr->sampsize;
s0 = (float)mixer_GetSampleInt (d0, mixer_chansize);
s1 = (float)mixer_GetSampleInt (d1, mixer_chansize);
s0 = mixer_GetSampleInt (d0, mixer_chansize);
s1 = mixer_GetSampleInt (d1, mixer_chansize);
return s0 + t * (s1 - s0);
}
@@ -1672,10 +1672,10 @@ mixer_UpsampleCubic (mixer_Source *src, bool left)
d3 = d2 + curr->sampsize;
}
s0 = (float)mixer_GetSampleInt (d0, mixer_chansize);
s1 = (float)mixer_GetSampleInt (d1, mixer_chansize);
s2 = (float)mixer_GetSampleInt (d2, mixer_chansize);
s3 = (float)mixer_GetSampleInt (d3, mixer_chansize);
s0 = mixer_GetSampleInt (d0, mixer_chansize);
s1 = mixer_GetSampleInt (d1, mixer_chansize);
s2 = mixer_GetSampleInt (d2, mixer_chansize);
s3 = mixer_GetSampleInt (d3, mixer_chansize);
a = (3.0f * (s1 - s2) - s0 + s3) * 0.5f;
b = 2.0f * s2 + s0 - ((5.0f * s1 + s3) * 0.5f);
@@ -1 +1,2 @@
uqm_CFILES="audiodrv_nosound.c"
uqm_HFILES="audiodrv_nosound.h"
@@ -146,12 +146,6 @@ noSound_Init (audio_Driver *driver, sint32 flags)
return -1;
}
atexit (unInitAudio);
SetSFXVolume (sfxVolumeScale);
SetSpeechVolume (speechVolumeScale);
SetMusicVolume ((COUNT)musicVolume);
PlaybackTask = AssignTask (PlaybackTaskFunc, 1024,
"nosound audio playback");
@@ -215,7 +209,7 @@ PlaybackTaskFunc (void *data)
mixer_MixFake (NULL, stream, len);
delay = period - (GetTimeCounter () - entryTime);
if (delay > 0)
SleepThread (delay);
HibernateThread (delay);
}
HFree (stream);
+1
View File
@@ -1 +1,2 @@
uqm_CFILES="audiodrv_sdl.c"
uqm_HFILES="audiodrv_sdl.h"
+9 -1
View File
@@ -98,6 +98,8 @@ static const audio_Driver mixSDL_Driver =
};
static void audioCallback (void *userdata, Uint8 *stream, int len);
/*
* Initialization
*/
@@ -150,7 +152,7 @@ mixSDL_Init (audio_Driver *driver, sint32 flags)
desired.format = AUDIO_S16SYS;
desired.channels = 2;
desired.callback = mixer_MixChannels;
desired.callback = audioCallback;
log_add (log_Info, "Opening SDL audio device.");
#if SDL_MAJOR_VERSION > 1
@@ -278,6 +280,7 @@ mixSDL_Uninit (void)
HFree (sbuffer);
}
DestroyMutex (soundSource[i].stream_mutex);
soundSource[i].stream_mutex = 0;
mixSDL_DeleteSources (1, &soundSource[i].handle);
}
@@ -288,6 +291,11 @@ mixSDL_Uninit (void)
SDL_QuitSubSystem (SDL_INIT_AUDIO);
}
static void
audioCallback (void *userdata, Uint8 *stream, int len)
{
mixer_MixChannels (userdata, stream, len);
}
/*
* General

Some files were not shown because too many files have changed in this diff Show More