Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
O
openjazz
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PocketInsanity
openjazz
Commits
4cdf7392
Commit
4cdf7392
authored
Feb 15, 2010
by
alistert
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Changed the way files are found. Added full-screen command-line option.
parent
ca3b2f2f
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
227 additions
and
171 deletions
+227
-171
file.cpp
src/io/file.cpp
+31
-7
file.h
src/io/file.h
+15
-6
video.cpp
src/io/gfx/video.cpp
+45
-38
video.h
src/io/gfx/video.h
+3
-2
main.cpp
src/main.cpp
+130
-111
setupmenu.cpp
src/menu/setupmenu.cpp
+3
-7
No files found.
src/io/file.cpp
View file @
4cdf7392
...
@@ -8,7 +8,7 @@
...
@@ -8,7 +8,7 @@
* Part of the OpenJazz project
* Part of the OpenJazz project
*
*
*
*
* Copyright (c) 2005-20
09
Alister Thomson
* Copyright (c) 2005-20
10
Alister Thomson
*
*
* OpenJazz is distributed under the terms of
* OpenJazz is distributed under the terms of
* the GNU General Public License, version 2.0
* the GNU General Public License, version 2.0
...
@@ -27,14 +27,18 @@
...
@@ -27,14 +27,18 @@
File
::
File
(
const
char
*
name
,
bool
write
)
{
File
::
File
(
const
char
*
name
,
bool
write
)
{
// Open the file from the user's directory
Path
*
path
;
if
(
open
(
userPath
,
name
,
write
))
return
;
// Open the file from the OpenJazz directory
// Try opening the file from all the available directories
if
(
open
(
ojPath
,
name
,
write
))
return
;
// Open the file from the game directory
path
=
firstPath
;
if
(
open
(
gamePath
,
name
,
write
))
return
;
while
(
path
)
{
if
(
open
(
path
->
path
,
name
,
write
))
return
;
path
=
path
->
next
;
}
log
(
"Could not open file"
,
name
);
log
(
"Could not open file"
,
name
);
...
@@ -331,3 +335,23 @@ void File::loadPalette (SDL_Color *palette) {
...
@@ -331,3 +335,23 @@ void File::loadPalette (SDL_Color *palette) {
}
}
Path
::
Path
(
Path
*
newNext
,
char
*
newPath
)
{
next
=
newNext
;
path
=
newPath
;
return
;
}
Path
::~
Path
()
{
if
(
next
)
delete
next
;
delete
[]
path
;
return
;
}
src/io/file.h
View file @
4cdf7392
...
@@ -8,7 +8,7 @@
...
@@ -8,7 +8,7 @@
* Part of the OpenJazz project
* Part of the OpenJazz project
*
*
*
*
* Copyright (c) 2005-20
09
Alister Thomson
* Copyright (c) 2005-20
10
Alister Thomson
*
*
* OpenJazz is distributed under the terms of
* OpenJazz is distributed under the terms of
* the GNU General Public License, version 2.0
* the GNU General Public License, version 2.0
...
@@ -30,7 +30,7 @@
...
@@ -30,7 +30,7 @@
#include <stdio.h>
#include <stdio.h>
// Class
es
// Class
class
File
{
class
File
{
...
@@ -62,13 +62,22 @@ class File {
...
@@ -62,13 +62,22 @@ class File {
};
};
class
Path
{
// Variables
public
:
Path
*
next
;
char
*
path
;
Path
(
Path
*
newNext
,
char
*
newPath
);
~
Path
();
};
// Variable
// Paths to files
// Paths to files
EXTERN
char
*
userPath
;
EXTERN
Path
*
firstPath
;
EXTERN
char
*
ojPath
;
EXTERN
char
*
gamePath
;
#endif
#endif
src/io/gfx/video.cpp
View file @
4cdf7392
...
@@ -9,7 +9,7 @@
...
@@ -9,7 +9,7 @@
* Part of the OpenJazz project
* Part of the OpenJazz project
*
*
*
*
* Copyright (c) 2005-20
09
Alister Thomson
* Copyright (c) 2005-20
10
Alister Thomson
*
*
* OpenJazz is distributed under the terms of
* OpenJazz is distributed under the terms of
* the GNU General Public License, version 2.0
* the GNU General Public License, version 2.0
...
@@ -59,44 +59,51 @@ SDL_Surface * createSurface (unsigned char * pixels, int width, int height) {
...
@@ -59,44 +59,51 @@ SDL_Surface * createSurface (unsigned char * pixels, int width, int height) {
}
}
void
createFullscreen
()
{
SDL_ShowCursor
(
SDL_DISABLE
);
#ifdef WIZ
screen
=
SDL_SetVideoMode
(
screenW
,
screenH
,
8
,
SDL_FULLSCREEN
|
SDL_SWSURFACE
|
SDL_HWPALETTE
);
#else
screen
=
SDL_SetVideoMode
(
screenW
,
screenH
,
8
,
SDL_FULLSCREEN
|
SDL_DOUBLEBUF
|
SDL_HWSURFACE
|
SDL_HWPALETTE
);
#endif
SDL_SetPalette
(
screen
,
SDL_LOGPAL
,
logicalPalette
,
0
,
256
);
SDL_SetPalette
(
screen
,
SDL_PHYSPAL
,
currentPalette
,
0
,
256
);
/* A real 8-bit display is quite likely if the user has the right video
card, the right video drivers, the right version of DirectX/whatever, and
the right version of SDL. In other words, it's not likely enough. If a real
palette is assumed when
a) there really is a real palette, there will be an extremely small speed
gain.
b) the palette is emulated, there will be a HUGE speed loss.
Therefore, assume the palette is emulated. */
// TODO: Find a better way
fakePalette
=
true
;
return
;
}
#ifndef FULLSCREEN_ONLY
#ifndef FULLSCREEN_ONLY
void
toggleFullscreen
()
{
void
createWindow
()
{
fullscreen
=
!
fullscreen
;
screen
=
SDL_SetVideoMode
(
screenW
,
screenH
,
8
,
SDL_RESIZABLE
|
SDL_DOUBLEBUF
|
SDL_HWSURFACE
|
SDL_HWPALETTE
);
if
(
fullscreen
)
{
SDL_SetPalette
(
screen
,
SDL_LOGPAL
,
logicalPalette
,
0
,
256
);
SDL_ShowCursor
(
SDL_DISABLE
);
SDL_SetPalette
(
screen
,
SDL_PHYSPAL
,
currentPalette
,
0
,
256
);
screen
=
SDL_SetVideoMode
(
screenW
,
screenH
,
8
,
SDL_FULLSCREEN
|
SDL_DOUBLEBUF
|
SDL_HWSURFACE
|
SDL_HWPALETTE
);
SDL_ShowCursor
(
SDL_ENABLE
);
SDL_SetPalette
(
screen
,
SDL_LOGPAL
,
logicalPalette
,
0
,
256
);
SDL_SetPalette
(
screen
,
SDL_PHYSPAL
,
currentPalette
,
0
,
256
);
/* Assume that in windowed mode the palette is being emulated.
This is extremely likely. */
/* A real 8-bit display is quite likely if the user has the right video
// TODO: Find a better way
card, the right video drivers, the right version of DirectX/whatever,
fakePalette
=
true
;
and the right version of SDL. In other words, it's not likely enough.
If a real palette is assumed when
a) there really is a real palette, there will be an extremely small
speed gain.
b) the palette is emulated, there will be a HUGE speed loss.
Therefore, assume the palette is emulated. */
// TODO: Find a better way
fakePalette
=
true
;
}
else
{
screen
=
SDL_SetVideoMode
(
screenW
,
screenH
,
8
,
SDL_RESIZABLE
|
SDL_DOUBLEBUF
|
SDL_HWSURFACE
|
SDL_HWPALETTE
);
SDL_SetPalette
(
screen
,
SDL_LOGPAL
,
logicalPalette
,
0
,
256
);
SDL_SetPalette
(
screen
,
SDL_PHYSPAL
,
currentPalette
,
0
,
256
);
SDL_ShowCursor
(
SDL_ENABLE
);
/* Assume that in windowed mode the palette is being emulated.
This is extremely likely. */
// TODO: Find a better way
fakePalette
=
true
;
}
return
;
return
;
...
...
src/io/gfx/video.h
View file @
4cdf7392
...
@@ -9,7 +9,7 @@
...
@@ -9,7 +9,7 @@
* Part of the OpenJazz project
* Part of the OpenJazz project
*
*
*
*
* Copyright (c) 2005-20
09
Alister Thomson
* Copyright (c) 2005-20
10
Alister Thomson
*
*
* OpenJazz is distributed under the terms of
* OpenJazz is distributed under the terms of
* the GNU General Public License, version 2.0
* the GNU General Public License, version 2.0
...
@@ -57,8 +57,9 @@ EXTERN SDL_Surface *panelAmmo[5];
...
@@ -57,8 +57,9 @@ EXTERN SDL_Surface *panelAmmo[5];
EXTERN
SDL_Surface
*
createSurface
(
unsigned
char
*
pixels
,
int
width
,
EXTERN
SDL_Surface
*
createSurface
(
unsigned
char
*
pixels
,
int
width
,
int
height
);
int
height
);
EXTERN
void
createFullscreen
();
#ifndef FULLSCREEN_ONLY
#ifndef FULLSCREEN_ONLY
EXTERN
void
toggleFullscreen
();
EXTERN
void
createWindow
();
#endif
#endif
EXTERN
void
usePalette
(
SDL_Color
*
palette
);
EXTERN
void
usePalette
(
SDL_Color
*
palette
);
EXTERN
void
restorePalette
(
SDL_Surface
*
surface
);
EXTERN
void
restorePalette
(
SDL_Surface
*
surface
);
...
...
src/main.cpp
View file @
4cdf7392
...
@@ -12,7 +12,7 @@
...
@@ -12,7 +12,7 @@
* Part of the OpenJazz project
* Part of the OpenJazz project
*
*
*
*
* Copyright (c) 2005-20
09
Alister Thomson
* Copyright (c) 2005-20
10
Alister Thomson
*
*
* OpenJazz is distributed under the terms of
* OpenJazz is distributed under the terms of
* the GNU General Public License, version 2.0
* the GNU General Public License, version 2.0
...
@@ -54,25 +54,104 @@ extern int volume_direction;
...
@@ -54,25 +54,104 @@ extern int volume_direction;
#endif
#endif
int
loadMain
()
{
int
loadMain
(
int
argc
,
char
*
argv
[]
)
{
File
*
file
;
File
*
file
;
unsigned
char
*
pixels
,
*
sorted
;
unsigned
char
*
pixels
,
*
sorted
;
int
count
,
x
,
y
;
int
count
,
x
,
y
;
// Initialise video settings
// Determine paths
// Use the hard-coded path, if available
#ifdef DATAPATH
firstPath
=
new
Path
(
NULL
,
createString
(
DATAPATH
));
#elseifdef __SYMBIAN32__
#ifdef UIQ3
firstPath
=
new
Path
(
NULL
,
createString
(
"c:
\\
shared
\\
openjazz
\\
"
));
#else
firstPath
=
new
Path
(
NULL
,
createString
(
"c:
\\
data
\\
openjazz
\\
"
));
#endif
#else
firstPath
=
NULL
;
#endif
// Use any provided paths, appending a directory separator as necessary
for
(
count
=
1
;
count
<
argc
;
count
++
)
{
// If it isn't an option, it should be a path
if
(
argv
[
count
][
0
]
!=
'-'
)
{
#ifdef WIN32
if
(
argv
[
count
][
strlen
(
argv
[
count
])
-
1
]
!=
'\\'
)
{
firstPath
=
new
Path
(
firstPath
,
createString
(
argv
[
count
],
"
\\
"
));
#else
if
(
argv
[
count
][
strlen
(
argv
[
count
])
-
1
]
!=
'/'
)
{
firstPath
=
new
Path
(
firstPath
,
createString
(
argv
[
count
],
"/"
));
#endif
}
else
{
firstPath
=
new
Path
(
firstPath
,
createString
(
argv
[
count
]));
}
}
}
// Use the path of the program
count
=
strlen
(
argv
[
0
])
-
1
;
// Search for directory separator
#ifdef WIN32
while
((
argv
[
0
][
count
]
!=
'\\'
)
&&
(
count
>=
0
))
count
--
;
#else
while
((
argv
[
0
][
count
]
!=
'/'
)
&&
(
count
>=
0
))
count
--
;
#endif
// If a directory was found, copy it to the path
if
(
count
>
0
)
{
firstPath
=
new
Path
(
firstPath
,
new
char
[
count
+
2
]);
memcpy
(
firstPath
->
path
,
argv
[
0
],
count
+
1
);
firstPath
->
path
[
count
+
1
]
=
0
;
}
// Use the user's home directory, if available
#ifdef HOMEDIR
#ifdef WIN32
firstPath
=
new
Path
(
firstPath
,
createString
(
getenv
(
"HOME"
),
"
\\
"
));
#else
firstPath
=
new
Path
(
firstPath
,
createString
(
getenv
(
"HOME"
),
"/."
));
#endif
#endif
// Use the current working directory
firstPath
=
new
Path
(
firstPath
,
createString
(
""
));
// Default settings
// Video settings
screenW
=
320
;
screenW
=
320
;
screenH
=
200
;
screenH
=
200
;
#ifndef FULLSCREEN_ONLY
#ifndef FULLSCREEN_ONLY
fullscreen
=
false
;
fullscreen
=
false
;
#endif
#endif
// Assume that in windowed mode the palette is being emulated
// This is extremely likely
// TODO: Find a better way
fakePalette
=
true
;
firstPE
=
NULL
;
// Create the player's name
// Create the player's name
characterName
=
createEditableString
(
CHAR_NAME
);
characterName
=
createEditableString
(
CHAR_NAME
);
...
@@ -89,6 +168,7 @@ int loadMain () {
...
@@ -89,6 +168,7 @@ int loadMain () {
// Open config file
// Open config file
try
{
try
{
file
=
new
File
(
CONFIG_FILE
,
false
);
file
=
new
File
(
CONFIG_FILE
,
false
);
...
@@ -141,20 +221,32 @@ int loadMain () {
...
@@ -141,20 +221,32 @@ int loadMain () {
}
}
// Get command-line override
#ifndef FULLSCREEN_ONLY
for
(
count
=
1
;
count
<
argc
;
count
++
)
{
// If there's a hyphen, it should be an option
if
(
argv
[
count
][
0
]
==
'-'
)
{
if
(
argv
[
count
][
1
]
==
'f'
)
fullscreen
=
true
;
}
}
#endif
// Create the game's window
// Create the game's window
currentPalette
=
logicalPalette
;
#ifdef FULLSCREEN_ONLY
#ifdef FULLSCREEN_ONLY
#ifdef WIZ
createFullscreen
();
screen
=
SDL_SetVideoMode
(
screenW
,
screenH
,
8
,
SDL_FULLSCREEN
|
SDL_SWSURFACE
|
SDL_HWPALETTE
);
SDL_ShowCursor
(
SDL_DISABLE
);
#else
screen
=
SDL_SetVideoMode
(
screenW
,
screenH
,
8
,
SDL_FULLSCREEN
|
SDL_DOUBLEBUF
|
SDL_HWSURFACE
|
SDL_HWPALETTE
);
#endif
#else
#else
screen
=
SDL_SetVideoMode
(
screenW
,
screenH
,
8
,
if
(
fullscreen
)
createFullscreen
();
SDL_RESIZABLE
|
SDL_DOUBLEBUF
|
SDL_HWSURFACE
|
SDL_HWPALETTE
);
else
createWindow
(
);
#endif
#endif
if
(
!
screen
)
{
if
(
!
screen
)
{
...
@@ -163,6 +255,8 @@ int loadMain () {
...
@@ -163,6 +255,8 @@ int loadMain () {
delete
characterName
;
delete
characterName
;
delete
firstPath
;
return
E_VIDEO
;
return
E_VIDEO
;
}
}
...
@@ -180,6 +274,8 @@ int loadMain () {
...
@@ -180,6 +274,8 @@ int loadMain () {
restorePalette
(
screen
);
restorePalette
(
screen
);
firstPE
=
NULL
;
// Set up audio
// Set up audio
openAudio
();
openAudio
();
...
@@ -198,6 +294,8 @@ int loadMain () {
...
@@ -198,6 +294,8 @@ int loadMain () {
delete
characterName
;
delete
characterName
;
delete
firstPath
;
return
e
;
return
e
;
}
}
...
@@ -314,6 +412,8 @@ int loadMain () {
...
@@ -314,6 +412,8 @@ int loadMain () {
delete
[]
characterName
;
delete
[]
characterName
;
delete
firstPath
;
delete
file
;
delete
file
;
return
e
;
return
e
;
...
@@ -424,6 +524,8 @@ void freeMain () {
...
@@ -424,6 +524,8 @@ void freeMain () {
delete
[]
characterName
;
delete
[]
characterName
;
delete
firstPath
;
return
;
return
;
...
@@ -453,7 +555,14 @@ int loop (int type) {
...
@@ -453,7 +555,14 @@ int loop (int type) {
#ifndef FULLSCREEN_ONLY
#ifndef FULLSCREEN_ONLY
// If Alt + Enter has been pressed, go to full screen
// If Alt + Enter has been pressed, go to full screen
if
((
event
.
key
.
keysym
.
sym
==
SDLK_RETURN
)
&&
if
((
event
.
key
.
keysym
.
sym
==
SDLK_RETURN
)
&&
(
event
.
key
.
keysym
.
mod
&
KMOD_ALT
))
toggleFullscreen
();
(
event
.
key
.
keysym
.
mod
&
KMOD_ALT
))
{
fullscreen
=
!
fullscreen
;
if
(
fullscreen
)
createFullscreen
();
else
createWindow
();
}
#endif
#endif
#ifdef WIZ
#ifdef WIZ
SDL_ShowCursor
(
SDL_DISABLE
);
SDL_ShowCursor
(
SDL_DISABLE
);
...
@@ -554,81 +663,6 @@ int main(int argc, char *argv[]) {
...
@@ -554,81 +663,6 @@ int main(int argc, char *argv[]) {
/*
/*
Scene *scene;
Scene *scene;
*/
*/
int
count
;
// Determine user path
#ifdef HOMEDIR
#ifdef WIN32
userPath
=
createString
(
getenv
(
"HOME"
),
"
\\
"
);
#else
userPath
=
createString
(
getenv
(
"HOME"
),
"/."
);
#endif
#else
userPath
=
createString
(
""
);
#endif
// Determine OpenJazz path
// Use the path of the program, if available
count
=
strlen
(
argv
[
0
])
-
1
;
// Search for directory separator
#ifdef WIN32
while
((
argv
[
0
][
count
]
!=
'\\'
)
&&
(
count
>=
0
))
count
--
;
#else
while
((
argv
[
0
][
count
]
!=
'/'
)
&&
(
count
>=
0
))
count
--
;
#endif
// If a directory was found, copy it to the path
if
(
count
>=
0
)
{
ojPath
=
new
char
[
count
+
2
];
memcpy
(
ojPath
,
argv
[
0
],
count
+
1
);
ojPath
[
count
+
1
]
=
0
;
}
else
ojPath
=
createString
(
""
);
// Determine game path
#ifdef DATAPATH
gamePath
=
createString
(
DATAPATH
);
#elseifdef __SYMBIAN32__
#ifdef UIQ3
gamePath
=
createString
(
"c:
\\
shared
\\
openjazz
\\
"
);
#else
gamePath
=
createString
(
"c:
\\
data
\\
openjazz
\\
"
);
#endif
#else
if
(
argc
>=
2
)
{
// Copy the provided path, appending a directory separator as necessary
#ifdef WIN32
if
(
argv
[
1
][
strlen
(
argv
[
1
])
-
1
]
!=
'\\'
)
{
gamePath
=
createString
(
argv
[
1
],
"
\\
"
);
#else
if
(
argv
[
1
][
strlen
(
argv
[
1
])
-
1
]
!=
'/'
)
{
gamePath
=
createString
(
argv
[
1
],
"/"
);
#endif
}
else
{
gamePath
=
createString
(
argv
[
1
]);
}
}
else
gamePath
=
createString
(
""
);
#endif
// Initialise SDL
// Initialise SDL
...
@@ -644,12 +678,9 @@ int main(int argc, char *argv[]) {
...
@@ -644,12 +678,9 @@ int main(int argc, char *argv[]) {
// Load universal game data and establish a window
// Load universal game data and establish a window
if
(
loadMain
()
!=
E_NONE
)
{
if
(
loadMain
(
argc
,
argv
)
!=
E_NONE
)
{
SDL_Quit
();
SDL_Quit
();
delete
[]
ojPath
;
delete
[]
gamePath
;
delete
[]
userPath
;
return
-
1
;
return
-
1
;
...
@@ -666,9 +697,6 @@ int main(int argc, char *argv[]) {
...
@@ -666,9 +697,6 @@ int main(int argc, char *argv[]) {
freeMain();
freeMain();
SDL_Quit();
SDL_Quit();
delete[] ojPath;
delete[] gamePath;
delete[] userPath;
return e;
return e;
...
@@ -688,9 +716,6 @@ int main(int argc, char *argv[]) {
...
@@ -688,9 +716,6 @@ int main(int argc, char *argv[]) {
freeMain
();
freeMain
();
SDL_Quit
();
SDL_Quit
();
delete
[]
ojPath
;
delete
[]
gamePath
;
delete
[]
userPath
;
return
e
;
return
e
;
...
@@ -710,9 +735,6 @@ int main(int argc, char *argv[]) {
...
@@ -710,9 +735,6 @@ int main(int argc, char *argv[]) {
delete menu;
delete menu;
freeMain();
freeMain();
SDL_Quit();
SDL_Quit();
delete[] ojPath;
delete[] gamePath;
delete[] userPath;
return e;
return e;
...
@@ -733,9 +755,6 @@ int main(int argc, char *argv[]) {
...
@@ -733,9 +755,6 @@ int main(int argc, char *argv[]) {
freeMain
();
freeMain
();
SDL_Quit
();
SDL_Quit
();
delete
[]
ojPath
;
delete
[]
gamePath
;
delete
[]
userPath
;
return
0
;
return
0
;
...
...
src/menu/setupmenu.cpp
View file @
4cdf7392
...
@@ -9,7 +9,7 @@
...
@@ -9,7 +9,7 @@
* Part of the OpenJazz project
* Part of the OpenJazz project
*
*
*
*
* Copyright (c) 2005-20
09
Alister Thomson
* Copyright (c) 2005-20
10
Alister Thomson
*
*
* OpenJazz is distributed under the terms of
* OpenJazz is distributed under the terms of
* the GNU General Public License, version 2.0
* the GNU General Public License, version 2.0
...
@@ -408,12 +408,8 @@ int Menu::setupResolution () {
...
@@ -408,12 +408,8 @@ int Menu::setupResolution () {
playSound
(
S_ORB
);
playSound
(
S_ORB
);
screen
=
SDL_SetVideoMode
(
screenW
,
screenH
,
8
,
if
(
fullscreen
)
createFullscreen
();
(
fullscreen
?
SDL_FULLSCREEN
:
SDL_RESIZABLE
)
|
SDL_DOUBLEBUF
|
else
createWindow
();
SDL_HWSURFACE
|
SDL_HWPALETTE
);
SDL_SetPalette
(
screen
,
SDL_LOGPAL
,
logicalPalette
,
0
,
256
);
SDL_SetPalette
(
screen
,
SDL_PHYSPAL
,
currentPalette
,
0
,
256
);
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment