Compare commits

...

2 Commits

Author SHA1 Message Date
9e8f04e9b4 Updates for bazel on windows. 2023-05-17 14:26:26 -07:00
a8c0ef05fb Adds clang-format config file. 2023-04-27 23:00:23 -07:00
85 changed files with 3049 additions and 5836 deletions

260
.clang-format Normal file
View File

@@ -0,0 +1,260 @@
---
# https://clang.llvm.org/docs/ClangFormatStyleOptions.html
Language: Cpp
# BasedOnStyle: Google
AccessModifierOffset: -1
AlignAfterOpenBracket: Align
AlignArrayOfStructures: None
AlignConsecutiveAssignments:
Enabled: false
AcrossEmptyLines: false
AcrossComments: false
AlignCompound: false
PadOperators: true
AlignConsecutiveBitFields:
Enabled: false
AcrossEmptyLines: false
AcrossComments: false
AlignCompound: false
PadOperators: false
AlignConsecutiveDeclarations:
Enabled: false
AcrossEmptyLines: false
AcrossComments: false
AlignCompound: false
PadOperators: false
AlignConsecutiveMacros:
Enabled: false
AcrossEmptyLines: false
AcrossComments: false
AlignCompound: false
PadOperators: false
AlignEscapedNewlines: Left
AlignOperands: AlignAfterOperator
AlignTrailingComments:
Kind: Always
OverEmptyLines: 0
AllowAllArgumentsOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: Never
AllowShortCaseLabelsOnASingleLine: false
AllowShortEnumsOnASingleLine: true
AllowShortFunctionsOnASingleLine: Inline
AllowShortIfStatementsOnASingleLine: WithoutElse
AllowShortLambdasOnASingleLine: All
AllowShortLoopsOnASingleLine: true
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: true
AlwaysBreakTemplateDeclarations: Yes
AttributeMacros:
- __capability
BinPackArguments: true
BinPackParameters: true
BitFieldColonSpacing: Both
BraceWrapping:
AfterCaseLabel: false
AfterClass: false
AfterControlStatement: Never
AfterEnum: false
AfterExternBlock: false
AfterFunction: false
AfterNamespace: false
AfterObjCDeclaration: false
AfterStruct: false
AfterUnion: false
BeforeCatch: false
BeforeElse: false
BeforeLambdaBody: false
BeforeWhile: false
IndentBraces: false
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
BreakAfterAttributes: Never
BreakAfterJavaFieldAnnotations: false
BreakArrays: true
BreakBeforeBinaryOperators: NonAssignment
BreakBeforeConceptDeclarations: Always
BreakBeforeBraces: Attach
BreakBeforeInlineASMColon: OnlyMultiline
BreakBeforeTernaryOperators: true
BreakConstructorInitializers: BeforeColon
BreakInheritanceList: BeforeColon
BreakStringLiterals: true
ColumnLimit: 120
CommentPragmas: '^ IWYU pragma:'
CompactNamespaces: false
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DerivePointerAlignment: false
DisableFormat: false
EmptyLineAfterAccessModifier: Never
EmptyLineBeforeAccessModifier: LogicalBlock
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: true
ForEachMacros:
- foreach
- Q_FOREACH
- BOOST_FOREACH
IfMacros:
- KJ_IF_MAYBE
IncludeBlocks: Regroup
IncludeCategories:
- Regex: '^<ext/.*\.h>'
Priority: 2
SortPriority: 0
CaseSensitive: false
- Regex: '^<.*\.h>'
Priority: 1
SortPriority: 0
CaseSensitive: false
- Regex: '^<.*'
Priority: 2
SortPriority: 0
CaseSensitive: false
- Regex: '.*'
Priority: 3
SortPriority: 0
CaseSensitive: false
IncludeIsMainRegex: '([-_](test|unittest))?$'
IncludeIsMainSourceRegex: ''
IndentAccessModifiers: false
IndentCaseBlocks: false
IndentCaseLabels: true
IndentExternBlock: AfterExternBlock
IndentGotoLabels: true
IndentPPDirectives: None
IndentRequiresClause: true
IndentWidth: 2
IndentWrappedFunctionNames: false
InsertBraces: false
InsertNewlineAtEOF: false
InsertTrailingCommas: None
IntegerLiteralSeparator:
Binary: 0
#BinaryMinDigits: 0
Decimal: 0
#DecimalMinDigits: 0
Hex: 0
#HexMinDigits: 0
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: false
LambdaBodyIndentation: Signature
LineEnding: DeriveLF
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCBinPackProtocolList: Never
ObjCBlockIndentWidth: 2
ObjCBreakBeforeNestedBlockParam: true
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
PackConstructorInitializers: NextLine
PenaltyBreakAssignment: 2
PenaltyBreakBeforeFirstCallParameter: 1
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakOpenParenthesis: 0
PenaltyBreakString: 1000
PenaltyBreakTemplateDeclaration: 10
PenaltyExcessCharacter: 1000000
PenaltyIndentedWhitespace: 0
PenaltyReturnTypeOnItsOwnLine: 200
PointerAlignment: Left
PPIndentWidth: -1
QualifierAlignment: Leave
RawStringFormats:
- Language: Cpp
Delimiters:
- cc
- CC
- cpp
- Cpp
- CPP
- 'c++'
- 'C++'
CanonicalDelimiter: ''
BasedOnStyle: google
- Language: TextProto
Delimiters:
- pb
- PB
- proto
- PROTO
EnclosingFunctions:
- EqualsProto
- EquivToProto
- PARSE_PARTIAL_TEXT_PROTO
- PARSE_TEST_PROTO
- PARSE_TEXT_PROTO
- ParseTextOrDie
- ParseTextProtoOrDie
- ParseTestProto
- ParsePartialTestProto
CanonicalDelimiter: pb
BasedOnStyle: google
ReferenceAlignment: Pointer
ReflowComments: true
RemoveBracesLLVM: false
RemoveSemicolon: false
RequiresClausePosition: OwnLine
RequiresExpressionIndentation: OuterScope
SeparateDefinitionBlocks: Always
ShortNamespaceLines: 1
SortIncludes: CaseSensitive
SortJavaStaticImport: Before
SortUsingDeclarations: LexicographicNumeric
SpaceAfterCStyleCast: false
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: true
SpaceAroundPointerQualifiers: Default
SpaceBeforeAssignmentOperators: true
SpaceBeforeCaseColon: false
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements
SpaceBeforeParensOptions:
AfterControlStatements: true
AfterForeachMacros: true
AfterFunctionDefinitionName: false
AfterFunctionDeclarationName: false
AfterIfMacros: true
AfterOverloadedOperator: false
AfterRequiresInClause: false
AfterRequiresInExpression: false
BeforeNonEmptyParentheses: false
SpaceBeforeRangeBasedForLoopColon: true
SpaceBeforeSquareBrackets: false
SpaceInEmptyBlock: false
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 2
SpacesInAngles: Never
SpacesInConditionalStatement: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInLineCommentPrefix:
Minimum: 1
Maximum: -1
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Auto
StatementAttributeLikeMacros:
- Q_EMIT
StatementMacros:
- Q_UNUSED
- QT_REQUIRE_VERSION
TabWidth: 8
UseTab: Never
WhitespaceSensitiveMacros:
- BOOST_PP_STRINGIZE
- CF_SWIFT_NAME
- NS_SWIFT_NAME
- PP_STRINGIZE
- STRINGIZE
...

1
.gitignore vendored
View File

@@ -1 +1,2 @@
/bazel-* /bazel-*
/.vscode

321
BUILD
View File

@@ -4,21 +4,67 @@ cc_library(
name = "axis_motion_event", name = "axis_motion_event",
srcs = ["AxisMotionEvent.cpp"], srcs = ["AxisMotionEvent.cpp"],
hdrs = ["AxisMotionEvent.h"], hdrs = ["AxisMotionEvent.h"],
visibility = ["//visibility:public"],
) )
cc_library( cc_library(
name = "bmp", name = "bmp",
srcs = ["bmp.cpp"], srcs = ["bmp.cpp"],
hdrs = ["bmp.h"], hdrs = ["bmp.h"],
deps = ["texture"], visibility = ["//visibility:public"],
deps = [
":config",
":image",
":logger",
":opengl",
":texture",
],
) )
cc_library( cc_library(
name = "camera", name = "camera",
srcs = ["camera.cpp"], srcs = ["camera.cpp"],
hdrs = ["camera.h"], hdrs = ["camera.h"],
visibility = ["//visibility:public"],
deps = [ deps = [
"window", ":config",
":window",
],
)
cc_test(
name = "camera_test",
srcs = ["camera_test.cpp"],
deps = [
":camera",
":config",
"@TinyTest//:tinytest",
],
)
cc_library(
name = "config",
hdrs = ["config.h"],
visibility = ["//visibility:public"],
)
cc_library(
name = "console_logger",
srcs = ["console_logger.cpp"],
hdrs = ["console_logger.h"],
visibility = ["//visibility:public"],
deps = [
":config",
":logger",
],
)
cc_test(
name = "console_logger_test",
srcs = ["console_logger_test.cpp"],
deps = [
"console_logger",
"@TinyTest//:tinytest",
], ],
) )
@@ -26,9 +72,11 @@ cc_library(
name = "ctrls", name = "ctrls",
srcs = ["ctrls.cpp"], srcs = ["ctrls.cpp"],
hdrs = ["ctrls.h"], hdrs = ["ctrls.h"],
visibility = ["//visibility:public"],
deps = [ deps = [
"keys", ":config",
"strmanip", ":keys",
":strmanip",
], ],
) )
@@ -36,10 +84,12 @@ cc_library(
name = "draw_event", name = "draw_event",
srcs = ["DrawEvent.cpp"], srcs = ["DrawEvent.cpp"],
hdrs = ["DrawEvent.h"], hdrs = ["DrawEvent.h"],
visibility = ["//visibility:public"],
deps = [ deps = [
"event", ":config",
"level", ":event",
"main", ":level",
":main",
], ],
) )
@@ -47,43 +97,66 @@ cc_library(
name = "event", name = "event",
srcs = ["Event.cpp"], srcs = ["Event.cpp"],
hdrs = ["Event.h"], hdrs = ["Event.h"],
deps = ["object"], visibility = ["//visibility:public"],
deps = [
":config",
":object",
],
) )
cc_library( cc_library(
name = "event_manager", name = "event_manager",
srcs = ["EventManager.cpp"], srcs = ["EventManager.cpp"],
hdrs = ["EventManager.h"], hdrs = ["EventManager.h"],
visibility = ["//visibility:public"],
deps = [ deps = [
"event", ":config",
"list", ":event",
], ],
) )
cc_library( cc_library(
name = "geometry", name = "geometry",
srcs = ["geometry.cpp"],
hdrs = ["geometry.h"], hdrs = ["geometry.h"],
visibility = ["//visibility:public"],
deps = [
":mygl_texture",
":vector",
],
) )
cc_library( cc_library(
name = "image", name = "image",
srcs = ["image.cpp"],
hdrs = ["image.h"], hdrs = ["image.h"],
visibility = ["//visibility:public"],
deps = [
":config",
":logger",
":opengl",
":texture",
],
) )
cc_library( cc_library(
name = "keys", name = "keys",
srcs = ["keys.cpp"], srcs = ["keys.cpp"],
hdrs = ["keys.h"], hdrs = ["keys.h"],
visibility = ["//visibility:public"],
deps = [":config"],
) )
cc_library( cc_library(
name = "key_press_event", name = "key_press_event",
srcs = ["KeyPressEvent.cpp"], srcs = ["KeyPressEvent.cpp"],
hdrs = ["KeyPressEvent.h"], hdrs = ["KeyPressEvent.h"],
visibility = ["//visibility:public"],
deps = [ deps = [
"event", ":config",
"keys", ":event",
"main", ":keys",
":main",
], ],
) )
@@ -91,10 +164,12 @@ cc_library(
name = "key_release_event", name = "key_release_event",
srcs = ["KeyReleaseEvent.cpp"], srcs = ["KeyReleaseEvent.cpp"],
hdrs = ["KeyReleaseEvent.h"], hdrs = ["KeyReleaseEvent.h"],
visibility = ["//visibility:public"],
deps = [ deps = [
"event", ":config",
"keys", ":event",
"main", ":keys",
":main",
], ],
) )
@@ -102,59 +177,63 @@ cc_library(
name = "level", name = "level",
srcs = ["level.cpp"], srcs = ["level.cpp"],
hdrs = ["level.h"], hdrs = ["level.h"],
visibility = ["//visibility:public"],
deps = [ deps = [
"bmp", ":bmp",
"camera", ":camera",
"geometry", ":config",
"keys", ":geometry",
"list", ":keys",
"mydefs", ":logger",
"mygl_font", ":mydefs",
"mygl_texture", ":mygl_font",
"player", ":mygl_texture",
"strmanip", ":player",
"tga", ":strmanip",
"vector", ":tga",
"version", ":vector",
":version",
], ],
) )
cc_library( cc_library(
name = "linux", name = "linux",
srcs = ["linux.cpp"], srcs = ["linux.cpp"],
) visibility = ["//visibility:public"],
cc_library(
name = "list",
hdrs = ["list.h"],
) )
cc_library( cc_library(
name = "logger", name = "logger",
srcs = ["Logger.cpp"],
hdrs = ["Logger.h"], hdrs = ["Logger.h"],
visibility = ["//visibility:public"],
) )
cc_binary( cc_binary(
name = "macosx", name = "macosx",
srcs = ["macosx.cpp"], srcs = ["macosx.cpp"],
copts = ["-framework OpenGL"], copts = ["-framework OpenGL"],
target_compatible_with = ["@platforms//os:macos"],
deps = [ deps = [
"draw_event", ":config",
"event_manager", ":draw_event",
"key_press_event", ":event_manager",
"key_release_event", ":key_press_event",
"main", ":key_release_event",
"version", ":main",
"x11", ":version",
":x11",
], ],
) )
cc_library( cc_library(
name = "main", name = "main",
hdrs = ["main.h"], hdrs = ["main.h"],
visibility = ["//visibility:public"],
deps = [ deps = [
"level", ":config",
"world_defs", ":level",
":world_defs",
], ],
) )
@@ -162,23 +241,29 @@ cc_library(
name = "model", name = "model",
srcs = ["Model.cpp"], srcs = ["Model.cpp"],
hdrs = ["Model.h"], hdrs = ["Model.h"],
visibility = ["//visibility:public"],
deps = [":config"],
) )
cc_library( cc_library(
name = "mydefs", name = "mydefs",
hdrs = ["mydefs.h"], hdrs = ["mydefs.h"],
visibility = ["//visibility:public"],
) )
cc_library( cc_library(
name = "mygl", name = "mygl",
srcs = ["mygl.cpp"], srcs = ["mygl.cpp"],
hdrs = ["mygl.h"], hdrs = ["mygl.h"],
visibility = ["//visibility:public"],
deps = [ deps = [
"bmp", ":bmp",
"strmanip", ":config",
"texture", ":logger",
"tga", ":strmanip",
"window", ":texture",
":tga",
":window",
], ],
) )
@@ -186,56 +271,48 @@ cc_library(
name = "mygl_font", name = "mygl_font",
srcs = ["myglFont.cpp"], srcs = ["myglFont.cpp"],
hdrs = ["myglFont.h"], hdrs = ["myglFont.h"],
deps = ["mygl"], visibility = ["//visibility:public"],
deps = [
":config",
":mygl",
],
) )
cc_library( cc_library(
name = "mygl_texture", name = "mygl_texture",
srcs = ["myglTexture.cpp"], srcs = ["myglTexture.cpp"],
hdrs = ["myglTexture.h"], hdrs = ["myglTexture.h"],
deps = ["mygl"], visibility = ["//visibility:public"],
deps = [
":config",
":logger",
":mygl",
],
) )
cc_library( cc_library(
name = "null_video_plugin", name = "opengl",
srcs = ["NullVideoPlugin.cpp"], hdrs = ["opengl.h"],
hdrs = ["NullVideoPlugin.h"], visibility = ["//visibility:public"],
deps = [
"video_plugin",
],
) )
cc_library( cc_library(
name = "object", name = "object",
srcs = ["Object.cpp"], srcs = ["Object.cpp"],
hdrs = ["Object.h"], hdrs = ["Object.h"],
visibility = ["//visibility:public"],
) )
cc_library( cc_library(
name = "player", name = "player",
srcs = ["player.cpp"], srcs = ["player.cpp"],
hdrs = ["player.h"], hdrs = ["player.h"],
visibility = ["//visibility:public"],
deps = [ deps = [
"camera", ":camera",
"ctrls", ":config",
"event_manager", ":ctrls",
], ":event_manager",
)
cc_library(
name = "plugin",
hdrs = ["Plugin.h"],
)
cc_library(
name = "plugin_manager",
srcs = ["PluginManager.cpp"],
hdrs = ["PluginManager.h"],
deps = [
"list",
"null_video_plugin",
"plugin",
"video_plugin",
], ],
) )
@@ -243,88 +320,144 @@ cc_library(
name = "point", name = "point",
srcs = ["Point.cpp"], srcs = ["Point.cpp"],
hdrs = ["Point.h"], hdrs = ["Point.h"],
visibility = ["//visibility:public"],
) )
cc_library( cc_library(
name = "rectangle", name = "rectangle",
srcs = ["Rectangle.cpp"], srcs = ["Rectangle.cpp"],
hdrs = ["Rectangle.h"], hdrs = ["Rectangle.h"],
visibility = ["//visibility:public"],
) )
cc_library( cc_library(
name = "screen", name = "screen",
srcs = ["screen.cpp"], srcs = ["screen.cpp"],
hdrs = ["screen.h"], hdrs = ["screen.h"],
visibility = ["//visibility:public"],
deps = [":config"],
) )
cc_library( cc_library(
name = "strmanip", name = "strmanip",
srcs = ["strmanip.cpp"], srcs = ["strmanip.cpp"],
hdrs = ["strmanip.h"], hdrs = ["strmanip.h"],
deps = ["keys"], visibility = ["//visibility:public"],
deps = [
":config",
":keys",
],
) )
cc_library( cc_library(
name = "texture", name = "texture",
hdrs = ["texture.h"], hdrs = ["texture.h"],
visibility = ["//visibility:public"],
) )
cc_library( cc_library(
name = "tga", name = "tga",
srcs = ["tga.cpp"], srcs = ["tga.cpp"],
hdrs = ["tga.h"], hdrs = ["tga.h"],
deps = ["texture"], visibility = ["//visibility:public"],
deps = [
":config",
":image",
":logger",
":opengl",
":texture",
],
) )
cc_library( cc_library(
name = "vector", name = "vector",
srcs = ["vector.cpp"], srcs = ["vector.cpp"],
hdrs = ["vector.h"], hdrs = ["vector.h"],
visibility = ["//visibility:public"],
deps = [":config"],
) )
cc_library( cc_library(
name = "version", name = "version",
hdrs = ["version.h"], hdrs = ["version.h"],
) visibility = ["//visibility:public"],
cc_library(
name = "video_plugin",
hdrs = ["VideoPlugin.h"],
deps = [
"plugin",
"window",
],
) )
cc_library( cc_library(
name = "window", name = "window",
srcs = ["window.cpp"], srcs = ["window.cpp"],
hdrs = ["window.h"], hdrs = ["window.h"],
visibility = ["//visibility:public"],
deps = [ deps = [
"screen", #<GL/gl.h> <GL/glu.h>
"vector", ":config",
":opengl",
":screen",
":vector",
], ],
) )
cc_library( cc_binary(
name = "windows", name = "windows",
srcs = ["windows.cpp"], srcs = ["windows.cpp"],
linkopts = ["/ENTRY:WinMainCRTStartup"],
target_compatible_with = ["@platforms//os:windows"],
deps = [
":bmp",
":camera",
":config",
":console_logger",
":ctrls",
":draw_event",
":event",
":event_manager",
":geometry",
":key_press_event",
":key_release_event",
":keys",
":level",
":logger",
":main",
":mydefs",
":mygl",
":mygl_font",
":mygl_texture",
":object",
":opengl",
":player",
":screen",
":strmanip",
":texture",
":tga",
":vector",
":version",
":windows_logger",
":world_defs",
"//opengl:window",
],
) )
cc_library( cc_library(
name = "windows_logger", name = "windows_logger",
srcs = ["WindowsLogger.cpp"], srcs = ["WindowsLogger.cpp"],
hdrs = ["WindowsLogger.h"], hdrs = ["WindowsLogger.h"],
deps = ["logger"], visibility = ["//visibility:public"],
deps = [
":config",
":logger",
],
) )
cc_library( cc_library(
name = "world_defs", name = "world_defs",
hdrs = ["worlddefs.h"], hdrs = [":worlddefs.h"],
visibility = ["//visibility:public"],
) )
cc_library( cc_library(
name = "x11", name = "x11",
srcs = ["x11.cpp"], srcs = [":x11.cpp"],
hdrs = ["x11.h"], hdrs = [":x11.h"],
visibility = ["//visibility:public"],
deps = [":config"],
) )

View File

@@ -17,10 +17,13 @@
* Free Software Foundation, Inc., * * Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/ ***************************************************************************/
#include "DrawEvent.h"
// clang-format off
#include "DrawEvent.h"
#include "main.h" #include "main.h"
// clang-format on
namespace OpenArena { namespace OpenArena {
DrawEvent::DrawEvent() { DrawEvent::DrawEvent() {

View File

@@ -17,12 +17,16 @@
* Free Software Foundation, Inc., * * Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/ ***************************************************************************/
#ifndef OpenArena__DrawEvent_h__ #ifndef OpenArena__DrawEvent_h__
#define OpenArena__DrawEvent_h__ #define OpenArena__DrawEvent_h__
// clang-format off
#include "config.h"
#include "Event.h" #include "Event.h"
#include "level.h" #include "level.h"
// clang-format on
namespace OpenArena { namespace OpenArena {
class DrawEvent : public OpenArena::Event { class DrawEvent : public OpenArena::Event {
public: public:
@@ -41,4 +45,4 @@ class DrawEvent : public OpenArena::Event {
}; };
}; // End namespace OpenArena }; // End namespace OpenArena
#endif // End OpenArena__DrawEvent_h__ #endif // End !defined(OpenArena__DrawEvent_h__)

View File

@@ -17,8 +17,12 @@
* Free Software Foundation, Inc., * * Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/ ***************************************************************************/
// clang-format off
#include "Event.h" #include "Event.h"
// clang-format on
namespace OpenArena { namespace OpenArena {
Event::Event() { Event::Event() {
SetEventType(UnknownEventType); SetEventType(UnknownEventType);

View File

@@ -17,10 +17,15 @@
* Free Software Foundation, Inc., * * Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/ ***************************************************************************/
#ifndef OpenArena__event_h__ #ifndef OpenArena__event_h__
#define OpenArena__event_h__ #define OpenArena__event_h__
// clang-format off
#include "config.h"
#include "Object.h" #include "Object.h"
// clang-format on
namespace OpenArena { namespace OpenArena {
class Event : public Object { class Event : public Object {
public: public:
@@ -53,4 +58,4 @@ class Event : public Object {
EventType _type; EventType _type;
}; };
} // End namespace OpenArena } // End namespace OpenArena
#endif // End OpenArena__event_h__ #endif // End !defined(OpenArena__event_h__)

View File

@@ -17,18 +17,22 @@
* Free Software Foundation, Inc., * * Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/ ***************************************************************************/
// clang-format off
#include "EventManager.h" #include "EventManager.h"
#include <cstdlib> #include <cstdlib>
#include <iostream> #include <iostream>
// clang-format on
namespace OpenArena { namespace OpenArena {
EventManager::EventManager() {} EventManager::EventManager() {}
void EventManager::SendEvent(Event* event) { void EventManager::SendEvent(Event* event) {
unsigned int index; unsigned int index;
for (index = 0; index < eventHandlers.Length(); index++) { for (index = 0; index < eventHandlers.size(); index++) {
Event::EventHandler* handler = eventHandlers[index]; Event::EventHandler* handler = eventHandlers[index];
if (handler->Handles(event->GetEventType())) { if (handler->Handles(event->GetEventType())) {
handler->HandleEvent(event); handler->HandleEvent(event);
@@ -55,6 +59,6 @@ void EventManager::SendEvent(Event event)
*/ */
void EventManager::RegisterEventHandler(Event::EventHandler* eventHandler) { void EventManager::RegisterEventHandler(Event::EventHandler* eventHandler) {
eventHandlers.Insert(eventHandler); eventHandlers.push_back(eventHandler);
} }
}; // namespace OpenArena }; // End namespace OpenArena

View File

@@ -17,11 +17,15 @@
* Free Software Foundation, Inc., * * Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/ ***************************************************************************/
#ifndef OpenArena__EventManager_h__ #ifndef OpenArena__EventManager_h__
#define OpenArena__EventManager_h__ #define OpenArena__EventManager_h__
// clang-format off
#include "config.h"
#include "Event.h" #include "Event.h"
#include "list.h" #include <vector>
// clang-format on
namespace OpenArena { namespace OpenArena {
class EventManager { class EventManager {
@@ -31,7 +35,7 @@ class EventManager {
void RegisterEventHandler(Event::EventHandler* eventHandler); void RegisterEventHandler(Event::EventHandler* eventHandler);
private: private:
list<Event::EventHandler*> eventHandlers; std::vector<Event::EventHandler*> eventHandlers;
}; };
} // End namespace OpenArena } // End namespace OpenArena
#endif // End OpenArena__EventManager_h__ #endif // End !defined(OpenArena__EventManager_h__)

View File

@@ -17,12 +17,14 @@
* Free Software Foundation, Inc., * * Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/ ***************************************************************************/
// clang-format off
#include "KeyPressEvent.h" #include "KeyPressEvent.h"
#include <cstdio> #include <cstdio>
#include "main.h" #include "main.h"
// clang-format on
namespace OpenArena { namespace OpenArena {
KeyPressEvent::KeyPressEvent(OpenArena::Keys key) { KeyPressEvent::KeyPressEvent(OpenArena::Keys key) {
printf("KeyPressEvent created"); printf("KeyPressEvent created");

View File

@@ -17,11 +17,17 @@
* Free Software Foundation, Inc., * * Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/ ***************************************************************************/
#ifndef OpenArena__KeyPressEvent_h__ #ifndef OpenArena__KeyPressEvent_h__
#define OpenArena__KeyPressEvent_h__ #define OpenArena__KeyPressEvent_h__
// clang-format off
#include "config.h"
#include <cstdint>
#include "Event.h" #include "Event.h"
#include "keys.h" #include "keys.h"
// clang-format on
namespace OpenArena { namespace OpenArena {
class KeyPressEvent : public Event { class KeyPressEvent : public Event {
public: public:

View File

@@ -17,12 +17,14 @@
* Free Software Foundation, Inc., * * Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/ ***************************************************************************/
// clang-format off
#include "KeyReleaseEvent.h" #include "KeyReleaseEvent.h"
#include <cstdio> #include <cstdio>
#include "main.h" #include "main.h"
// clang-format on
namespace OpenArena { namespace OpenArena {
KeyReleaseEvent::KeyReleaseEvent(OpenArena::Keys key) { KeyReleaseEvent::KeyReleaseEvent(OpenArena::Keys key) {
_key = key; _key = key;

View File

@@ -17,11 +17,16 @@
* Free Software Foundation, Inc., * * Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/ ***************************************************************************/
#ifndef OpenArena__KeyReleaseEvent_h__ #ifndef OpenArena__KeyReleaseEvent_h__
#define OpenArena__KeyReleaseEvent_h__ #define OpenArena__KeyReleaseEvent_h__
// clang-format off
#include "config.h"
#include "Event.h" #include "Event.h"
#include "keys.h" #include "keys.h"
// clang-format on
namespace OpenArena { namespace OpenArena {
class KeyReleaseEvent : public Event { class KeyReleaseEvent : public Event {
public: public:
@@ -43,4 +48,4 @@ class KeyReleaseEvent : public Event {
}; };
}; // End namespace OpenArena }; // End namespace OpenArena
#endif // OpenArena__KeyReleaseEvent_h__ #endif // !defined(OpenArena__KeyReleaseEvent_h__)

BIN
Logger.cpp Normal file

Binary file not shown.

145
Logger.h
View File

@@ -17,99 +17,78 @@
* Free Software Foundation, Inc., * * Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/ ***************************************************************************/
#ifndef OpenArena__Logger_h__ #ifndef OpenArena__Logger_h__
#define OpenArena__Logger_h__ #define OpenArena__Logger_h__
// clang-format off
#include <exception>
#include <memory>
#include <string>
#if defined HAVE_CONFIG_H // clang-format on
#include "config.h"
#endif
namespace OpenArena { namespace OpenArena {
/*!
* \brief
* Write brief comment for Logger here.
*
* Write detailed description for Logger here.
*
* \remarks
* Write remarks for Logger here.
*
* \see
* Separate items with the '|' character.
*/
class Logger { class Logger {
public: public:
/*! enum MessageType { Unknown = 0, Debug, Verbose, Info, Warning, Error, Wtf };
* \brief
* Write brief comment for MESSAGETYPE_DEBUG here.
*/
enum MessageType { MESSAGETYPE_ALL, MESSAGETYPE_NONE, MESSAGETYPE_INFORMATION, MESSAGETYPE_ERROR, MESSAGETYPE_DEBUG };
/*! Logger();
* \brief virtual ~Logger();
* Write brief comment for ~Logger here.
*
* \throws <exception class>
* Description of criteria for throwing this exception.
*
* Write detailed description for ~Logger here.
*
* \remarks
* Write remarks for ~Logger here.
*
* \see
* Separate items with the '|' character.
*/
virtual ~Logger(void) {}
/*! virtual void LogMessage(const MessageType& type, const std::string& message) const = 0;
* \brief virtual void LogError(const MessageType& type, const std::exception& ex) const = 0;
* Write brief comment for Log here. virtual void LogError(const MessageType& type, const std::string& message, const std::exception& ex) const = 0;
* virtual void SetMinType(const MessageType& type);
* \param message virtual void SetMaxType(const MessageType& type);
* Description of parameter message. virtual MessageType GetMinType() const;
* virtual MessageType GetMaxType() const;
* \param type
* Description of parameter type. // This one is special and annoying because it requires macros until the minimum standard is c++20.
* #if __cplusplus >= 202002L
* \throws <exception class> static void LogUnimplementedMethod(std::source_location = std::source_location::current());
* Description of criteria for throwing this exception. #else
* static void LogUnimplementedMethodReal(std::string method_name);
* Write detailed description for Log here. #endif
*
* \remarks static void LogUnhandledError(const std::exception& ex);
* Write remarks for Log here. static void LogUnimplementedFeature(const std::string& feature);
* static void LogWtf(const std::string& message);
* \see static void LogWtf(const std::exception& ex);
* Separate items with the '|' character. static void LogWtf(const std::string& message, const std::exception& ex);
*/ static void LogError(const std::string& message);
virtual void Log(const char* message, MessageType type = MESSAGETYPE_INFORMATION) = 0; static void LogError(const std::exception& ex);
/*! static void LogError(const std::string& message, const std::exception& ex);
* \brief static void LogWarning(const std::string& message);
* Write brief comment for Log here. static void LogWarning(const std::exception& ex);
* static void LogWarning(const std::string& message, const std::exception& ex);
* \param message static void LogInfo(const std::string& message);
* Description of parameter message. static void LogInfo(const std::exception& ex);
* static void LogInfo(const std::string& message, const std::exception& ex);
* \param classification static void LogDebug(const std::string& message);
* Description of parameter classification. static void LogDebug(const std::exception& ex);
* static void LogDebug(const std::string& message, const std::exception& ex);
* \param type static void LogVerbose(const std::string& message);
* Description of parameter type. static void LogVerbose(const std::exception& ex);
* static void LogVerbose(const std::string& message, const std::exception& ex);
* \throws <exception class> static void Log(const MessageType& type, const std::string& message);
* Description of criteria for throwing this exception. static void Log(const MessageType& type, const std::exception& ex);
* static void Log(const MessageType& type, const std::string& message, const std::exception& ex);
* Write detailed description for Log here. static void LogToDo(const std::string& message);
* static void Reset();
* \remarks static void AddLogger(std::shared_ptr<Logger> logger);
* Write remarks for Log here.
* private:
* \see MessageType min_type_;
* Separate items with the '|' character. MessageType max_type_;
*/
virtual void Log(const char* message, const char* classification, MessageType type = MESSAGETYPE_INFORMATION) = 0;
}; };
} // End namespace OpenArena } // End namespace OpenArena
#if __cplusplus >= 202002L
#elif defined __GNUC__
#define Logger ::LogUnimplementedMethod LogUnimplementedMethodReal(__PRETTY_FUNCTION__);
#else
#define LogUnimplementedMethod Logger::LogUnimplementedMethodReal(__FUNCTION__);
#endif
#endif // End !defined(OpenArena__Logger_h__) #endif // End !defined(OpenArena__Logger_h__)

View File

@@ -17,8 +17,12 @@
* Free Software Foundation, Inc., * * Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/ ***************************************************************************/
// clang-format off
#include "Model.h" #include "Model.h"
// clang-format on
namespace OpenArena { namespace OpenArena {
Model::Model() {} Model::Model() {}

View File

@@ -17,12 +17,14 @@
* Free Software Foundation, Inc., * * Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/ ***************************************************************************/
#ifndef OpenArena__Model_h__ #ifndef OpenArena__Model_h__
#define OpenArena__Model_h__ #define OpenArena__Model_h__
#if defined HAVE_CONFIG_H // clang-format off
#include "config.h" #include "config.h"
#endif
// clang-format on
namespace OpenArena { namespace OpenArena {

View File

@@ -1,118 +0,0 @@
/***************************************************************************
* Copyright (C) 2001-2023 by Tom Hicks *
* headhunter3@gmail.com *
* *
* 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 OpenArena__NullVideoPlugin_h__
#define OpenArena__NullVideoPlugin_h__
#if defined HAVE_CONFIG_H
#include "config.h"
#endif
#include "VideoPlugin.h"
namespace OpenArena {
/*!
* \brief
* Write brief comment for NullVideoPlugin here.
*
* Write detailed description for NullVideoPlugin here.
*
* \remarks
* Write remarks for NullVideoPlugin here.
*
* \see
* Separate items with the '|' character.
*/
class NullVideoPlugin : public OpenArena::VideoPlugin {
public:
/*!
* \brief
* Write brief comment for NullVideoPlugin here.
*
* \throws <exception class>
* Description of criteria for throwing this exception.
*
* Write detailed description for NullVideoPlugin here.
*
* \remarks
* Write remarks for NullVideoPlugin here.
*
* \see
* Separate items with the '|' character.
*/
NullVideoPlugin(void);
public:
/*!
* \brief
* Write brief comment for ~NullVideoPlugin here.
*
* \throws <exception class>
* Description of criteria for throwing this exception.
*
* Write detailed description for ~NullVideoPlugin here.
*
* \remarks
* Write remarks for ~NullVideoPlugin here.
*
* \see
* Separate items with the '|' character.
*/
virtual ~NullVideoPlugin(void);
/*!
* \brief
* Write brief comment for CreateNewWindow here.
*
* \param width
* Description of parameter width.
*
* \param height
* Description of parameter height.
*
* \param bpp
* Description of parameter bpp.
*
* \param fullscreen
* Description of parameter fullscreen.
*
* \param title
* Description of parameter title.
*
* \returns
* Write description of return value here.
*
* \throws <exception class>
* Description of criteria for throwing this exception.
*
* Write detailed description for CreateNewWindow here.
*
* \remarks
* Write remarks for CreateNewWindow here.
*
* \see
* Separate items with the '|' character.
*/
virtual Window* CreateNewWindow(
uint32_t width, uint32_t height, uint32_t bpp = 32, bool fullscreen = false, const char* title = NULL);
};
} // End namespace OpenArena
#endif // End !defined(OpenArena__NullVideoPlugin_h__)

View File

@@ -17,14 +17,22 @@
* Free Software Foundation, Inc., * * Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/ ***************************************************************************/
// clang-format off
#include "Object.h" #include "Object.h"
// clang-format on
namespace OpenArena { namespace OpenArena {
namespace {
const char kClassName_OpenArena_Object[] = "Object";
}
Object::Object() {} Object::Object() {}
Object::~Object() {} Object::~Object() {}
const char* Object::GetClassName() { const char* Object::GetClassName() {
return 0x0; return kClassName_OpenArena_Object;
} }
} // End namespace OpenArena } // End namespace OpenArena

View File

@@ -17,6 +17,7 @@
* Free Software Foundation, Inc., * * Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/ ***************************************************************************/
#ifndef OpenArena__Object_h__ #ifndef OpenArena__Object_h__
#define OpenArena__Object_h__ #define OpenArena__Object_h__
@@ -29,4 +30,4 @@ class Object {
}; };
}; // namespace OpenArena }; // namespace OpenArena
#endif // End OpenArena__Object_h__ #endif // End !defined(OpenArena__Object_h__)

View File

@@ -1,132 +0,0 @@
/***************************************************************************
* Copyright (C) 2001-2023 by Tom Hicks *
* headhunter3@gmail.com *
* *
* 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 OpenArena__PluginManager_h__
#define OpenArena__PluginManager_h__
#if defined HAVE_CONFIG_H
#include "config.h"
#endif
#include "Plugin.h"
#include "VideoPlugin.h"
#include "list.h"
namespace OpenArena {
/**
* Perhaps this class should be a singleton.
*/
/*!
* \brief
* Write brief comment for PluginManager here.
*
* Write detailed description for PluginManager here.
*
* \remarks
* Write remarks for PluginManager here.
*
* \see
* Separate items with the '|' character.
*/
class PluginManager {
private:
list<Plugin*> _plugins;
public:
/**
* Creates a new PluginManager object
*/
/*!
* \brief
* Write brief comment for PluginManager here.
*
* \throws <exception class>
* Description of criteria for throwing this exception.
*
* Write detailed description for PluginManager here.
*
* \remarks
* Write remarks for PluginManager here.
*
* \see
* Separate items with the '|' character.
*/
PluginManager(void);
/*!
* \brief
* Write brief comment for ~PluginManager here.
*
* \throws <exception class>
* Description of criteria for throwing this exception.
*
* Write detailed description for ~PluginManager here.
*
* \remarks
* Write remarks for ~PluginManager here.
*
* \see
* Separate items with the '|' character.
*/
~PluginManager(void);
/*!
* \brief
* Write brief comment for GetPluginsOfType here.
*
* \param type
* Description of parameter type.
*
* \returns
* Write description of return value here.
*
* \throws <exception class>
* Description of criteria for throwing this exception.
*
* Write detailed description for GetPluginsOfType here.
*
* \remarks
* Write remarks for GetPluginsOfType here.
*
* \see
* Separate items with the '|' character.
*/
list<Plugin*> GetPluginsOfType(Plugin::Type type);
/*!
* \brief
* Write brief comment for GetDefaultVideoPlugin here.
*
* \returns
* Write description of return value here.
*
* \throws <exception class>
* Description of criteria for throwing this exception.
*
* Write detailed description for GetDefaultVideoPlugin here.
*
* \remarks
* Write remarks for GetDefaultVideoPlugin here.
*
* \see
* Separate items with the '|' character.
*/
VideoPlugin* GetDefaultVideoPlugin(void);
};
} // End namespace OpenArena
#endif // End !defined(OpenArena__PluginManager_h__)

View File

@@ -17,4 +17,7 @@
* Free Software Foundation, Inc., * * Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/ ***************************************************************************/
// clang-format off
#include "Point.h" #include "Point.h"
// clang-format on

View File

@@ -17,6 +17,7 @@
* Free Software Foundation, Inc., * * Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/ ***************************************************************************/
#ifndef OpenArena__Point_h__ #ifndef OpenArena__Point_h__
#define OpenArena__Point_h__ #define OpenArena__Point_h__

View File

@@ -17,4 +17,7 @@
* Free Software Foundation, Inc., * * Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/ ***************************************************************************/
// clang-format off
#include "Rectangle.h" #include "Rectangle.h"
// clang-format on

View File

@@ -17,11 +17,12 @@
* Free Software Foundation, Inc., * * Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/ ***************************************************************************/
#ifndef __OpenArena_Rectangle_h__
#define __OpenArena_Rectangle_h__ #ifndef OpenArena__Rectangle_h__
#define OpenArena__Rectangle_h__
namespace OpenArena { namespace OpenArena {
class Rectangle {}; class Rectangle {};
}; // namespace OpenArena }; // namespace OpenArena
#endif // __OpenArena_Rectangle_h__ #endif // OpenArena__Rectangle_h__

View File

@@ -1,101 +0,0 @@
/***************************************************************************
* Copyright (C) 2001-2023 by Tom Hicks *
* headhunter3@gmail.com *
* *
* 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 OpenArena__VideoPlugin_h__
#define OpenArena__VideoPlugin_h__
#if defined HAVE_CONFIG_H
#include "config.h"
#endif
#include "Plugin.h"
#include "window.h"
namespace OpenArena {
/*!
* \brief
* Write brief comment for VideoPlugin here.
*
* Write detailed description for VideoPlugin here.
*
* \remarks
* Write remarks for VideoPlugin here.
*
* \see
* Separate items with the '|' character.
*/
class VideoPlugin : public Plugin {
public:
public:
/*!
* \brief
* Write brief comment for ~VideoPlugin here.
*
* \throws <exception class>
* Description of criteria for throwing this exception.
*
* Write detailed description for ~VideoPlugin here.
*
* \remarks
* Write remarks for ~VideoPlugin here.
*
* \see
* Separate items with the '|' character.
*/
virtual ~VideoPlugin() {}
/*!
* \brief
* Write brief comment for CreateNewWindow here.
*
* \param width
* Description of parameter width.
*
* \param height
* Description of parameter height.
*
* \param bpp
* Description of parameter bpp.
*
* \param fullscreen
* Description of parameter fullscreen.
*
* \param title
* Description of parameter title.
*
* \returns
* Write description of return value here.
*
* \throws <exception class>
* Description of criteria for throwing this exception.
*
* Write detailed description for CreateNewWindow here.
*
* \remarks
* Write remarks for CreateNewWindow here.
*
* \see
* Separate items with the '|' character.
*/
virtual Window* CreateNewWindow(
uint32_t width, uint32_t height, uint32_t bpp = 32, bool fullscreen = false, const char* title = NULL) = 0;
};
} // End namespace OpenArena
#endif // End !defined(OpenArena__VideoPlugin_h__)

View File

@@ -29,41 +29,15 @@ http_archive(
) )
http_archive( http_archive(
name = "bazel_skylib", name = "TinyTest",
sha256 = "f7be3474d42aae265405a592bb7da8e171919d74c16f082a5457840f06054728", sha256 = "d6729abbec6ac167635be7463d8c37ca54b08e506e61553236b50c5ad30e8736",
urls = ["https://github.com/bazelbuild/bazel-skylib/releases/download/1.2.1/bazel-skylib-1.2.1.tar.gz"], strip_prefix = "TinyTest-a4109d2f494fd3fd3cc47069239fd3c79f728d5a",
urls = ["https://github.com/headhunter45/TinyTest/archive/a4109d2f494fd3fd3cc47069239fd3c79f728d5a.zip"],
) )
http_archive( http_archive(
name = "build_bazel_rules_apple", name = "CPPUtils",
sha256 = "9e26307516c4d5f2ad4aee90ac01eb8cd31f9b8d6ea93619fc64b3cbc81b0944", sha256 = "f6464f02ba6c67e36058c3f6f06ff7fe3977340af3fdd350153f4aa15c628a6a",
url = "https://github.com/bazelbuild/rules_apple/releases/download/2.2.0/rules_apple.2.2.0.tar.gz", strip_prefix = "cpp-utils-e05fb1e0a4e6ba247a8cd4af13a3aefa23e456dd",
urls = ["https://github.com/headhunter45/cpp-utils/archive/e05fb1e0a4e6ba247a8cd4af13a3aefa23e456dd.zip"],
) )
load(
"@build_bazel_rules_apple//apple:repositories.bzl",
"apple_rules_dependencies",
)
apple_rules_dependencies()
load(
"@build_bazel_rules_swift//swift:repositories.bzl",
"swift_rules_dependencies",
)
swift_rules_dependencies()
load(
"@build_bazel_rules_swift//swift:extras.bzl",
"swift_rules_extra_dependencies",
)
swift_rules_extra_dependencies()
load(
"@build_bazel_apple_support//lib:repositories.bzl",
"apple_support_dependencies",
)
apple_support_dependencies()

View File

@@ -17,45 +17,100 @@
* Free Software Foundation, Inc., * * Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/ ***************************************************************************/
#ifdef WIN32
#include "WindowsLogger.h"
// Documentation for the windows api stuff used here is available at
// https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-messagebox
// clang-format off
#include "WindowsLogger.h"
#ifdef _WIN32
#include <windows.h> #include <windows.h>
#include <winuser.h>
#include <cstdlib> #include <cstdlib>
#include <exception>
#include <string>
#endif
// clang-format on
namespace OpenArena { namespace OpenArena {
WindowsLogger::WindowsLogger() { #ifdef _WIN32
_type = MESSAGETYPE_ALL; namespace {
using std::exception;
using std::string;
const string kDebugMessageTitle = "Debug";
const string kErrorMessageTitle = "ERROR";
const string kInfoMessageTitle = "Information";
const string kVerboseMessageTitle = "Verbose";
const string kWarningMessageTitle = "Warning";
const string kWtfMessageTitle = "How did you let this happen?";
const string kUnknownMessageTitle = "Unknown";
} // End namespace
WindowsLogger::WindowsLogger() {}
WindowsLogger::~WindowsLogger() {}
void WindowsLogger::LogMessage(const MessageType& type, const string& message) const {
MessageBox(NULL, message.c_str(), GetTitle(type).c_str(), MB_OK | GetIcon(type));
} }
WindowsLogger::~WindowsLogger(void) {} void WindowsLogger::LogError(const MessageType& type, const exception& ex) const {
Logger::LogToDo("Implement OpenArena::WindowsLogger::LogError(MessageType, exception)");
WindowsLogger::WindowsLogger(Logger::MessageType type) {
_type = type;
} }
void WindowsLogger::Log(const char* message, MessageType type) { void WindowsLogger::LogError(const MessageType& type, const std::string& message, const std::exception& ex) const {
Log(message, "unspecified", type); Logger::LogToDo("Implement OpenArena::WindowsLogger::LogError(MessageType, exception, message)");
} }
void WindowsLogger::Log(const char* message, const char* classification, MessageType type) { /*
if (_type != MESSAGETYPE_NONE || _type == type || _type == MESSAGETYPE_ALL) { MB_ICONEXCLAMATION - An exclamation point.
MessageBox(NULL, message, classification, MB_OK | GetIconFromMessageType(type)); MB_ICONWARNING - An exclamation point. Alias for MB_ICONEXCLAMATION.
MB_ICONINFORMATION - A lowercase i.
MB_ICONASTERISK - A lowercase i. Alias for MB_ICONINFORMATION.
MB_ICONQUESTION - A question mark. Don't use this, because it's confusing to users.
MB_ICONSTOP - A stop sign icon.
MB_ICONERROR - A stop sign icon. Alias for MB_ICONSTOP.
MB_ICONHAND - A stop sign icon. Alias for MB_ICONSTOP.
*/
uint32_t WindowsLogger::GetIcon(const MessageType& type) const {
switch (type) {
case MessageType::Debug:
return MB_ICONEXCLAMATION;
case MessageType::Error:
return MB_ICONSTOP;
case MessageType::Info:
return MB_ICONINFORMATION;
case MessageType::Verbose:
return MB_ICONINFORMATION;
case MessageType::Warning:
return MB_ICONEXCLAMATION;
case MessageType::Wtf:
return MB_ICONSTOP;
default:
return MB_ICONINFORMATION;
} }
} }
uint32 WindowsLogger::GetIconFromMessageType(MessageType type) { string WindowsLogger::GetTitle(const MessageType& type) const {
switch (type) { switch (type) {
case MESSAGETYPE_ERROR: case MessageType::Debug:
return MB_ICONERROR; return kDebugMessageTitle;
case MESSAGETYPE_INFORMATION: case MessageType::Error:
return MB_ICONINFORMATION; return kErrorMessageTitle;
case MESSAGETYPE_DEBUG: case MessageType::Info:
return MB_ICONWARNING; return kInfoMessageTitle;
case MessageType::Verbose:
return kVerboseMessageTitle;
case MessageType::Warning:
return kWarningMessageTitle;
case MessageType::Wtf:
return kWtfMessageTitle;
default: default:
return MB_ICONASTERISK; return kUnknownMessageTitle;
}; }
} }
}; // namespace OpenArena #endif
} // End namespace OpenArena
#ifdef WIN32
namespace OpenArena {}; // namespace OpenArena
#endif #endif

View File

@@ -17,153 +17,29 @@
* Free Software Foundation, Inc., * * Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/ ***************************************************************************/
#ifndef OpenArena__WindowsLogger_h__ #ifndef OpenArena__WindowsLogger_h__
#define OpenArena__WindowsLogger_h__ #define OpenArena__WindowsLogger_h__
// clang-format off
#include <cstdint> #include <cstdint>
#if defined HAVE_CONFIG_H #include <exception>
#include "config.h" #include <string>
#endif
#include "logger.h" #include "logger.h"
// clang-format on
namespace OpenArena { namespace OpenArena {
/*!
* \brief
* Write brief comment for WindowsLogger here.
*
* Write detailed description for WindowsLogger here.
*
* \remarks
* Write remarks for WindowsLogger here.
*
* \see
* Separate items with the '|' character.
*/
class WindowsLogger : public OpenArena::Logger { class WindowsLogger : public OpenArena::Logger {
private: private:
/*! uint32_t GetIcon(const MessageType& type) const;
* \brief std::string GetTitle(const MessageType& type) const;
* Write brief comment for GetIconFromMessageType here.
*
* \param type
* Description of parameter type.
*
* \returns
* Write description of return value here.
*
* \throws <exception class>
* Description of criteria for throwing this exception.
*
* Write detailed description for GetIconFromMessageType here.
*
* \remarks
* Write remarks for GetIconFromMessageType here.
*
* \see
* Separate items with the '|' character.
*/
uint32_t GetIconFromMessageType(MessageType type);
MessageType _type;
public: public:
/*!
* \brief
* Write brief comment for WindowsLogger here.
*
* \throws <exception class>
* Description of criteria for throwing this exception.
*
* Write detailed description for WindowsLogger here.
*
* \remarks
* Write remarks for WindowsLogger here.
*
* \see
* Separate items with the '|' character.
*/
WindowsLogger(); WindowsLogger();
/*!
* \brief
* Write brief comment for WindowsLogger here.
*
* \param type
* Description of parameter type.
*
* \throws <exception class>
* Description of criteria for throwing this exception.
*
* Write detailed description for WindowsLogger here.
*
* \remarks
* Write remarks for WindowsLogger here.
*
* \see
* Separate items with the '|' character.
*/
WindowsLogger(Logger::MessageType type);
/*!
* \brief
* Write brief comment for Log here.
*
* \param message
* Description of parameter message.
*
* \param type
* Description of parameter type.
*
* \throws <exception class>
* Description of criteria for throwing this exception.
*
* Write detailed description for Log here.
*
* \remarks
* Write remarks for Log here.
*
* \see
* Separate items with the '|' character.
*/
virtual void Log(const char* message, MessageType type = MESSAGETYPE_INFORMATION);
/*!
* \brief
* Write brief comment for Log here.
*
* \param message
* Description of parameter message.
*
* \param classification
* Description of parameter classification.
*
* \param type
* Description of parameter type.
*
* \throws <exception class>
* Description of criteria for throwing this exception.
*
* Write detailed description for Log here.
*
* \remarks
* Write remarks for Log here.
*
* \see
* Separate items with the '|' character.
*/
virtual void Log(const char* message, const char* classification, MessageType type = MESSAGETYPE_INFORMATION);
/*!
* \brief
* Write brief comment for ~WindowsLogger here.
*
* \throws <exception class>
* Description of criteria for throwing this exception.
*
* Write detailed description for ~WindowsLogger here.
*
* \remarks
* Write remarks for ~WindowsLogger here.
*
* \see
* Separate items with the '|' character.
*/
virtual ~WindowsLogger(); virtual ~WindowsLogger();
virtual void LogMessage(const MessageType& type, const std::string& message) const;
virtual void LogError(const MessageType& type, const std::exception& ex) const;
virtual void LogError(const MessageType& type, const std::string& message, const std::exception& ex) const;
}; };
} // namespace OpenArena } // namespace OpenArena

349
bmp.cpp
View File

@@ -17,18 +17,24 @@
* Free Software Foundation, Inc., * * Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/ ***************************************************************************/
#include <cstdio>
#ifdef WIN32
#include <windows.h>
#endif
#include <OpenGL/gl.h>
// clang-format off
#include "bmp.h" #include "bmp.h"
#ifdef WIN32 #include <cstdint>
#pragma warning(disable : 4996) #include <cstdio>
#endif #include <memory>
#include "Logger.h"
#include "opengl.h"
// clang-format on
namespace OpenArena { namespace OpenArena {
namespace {
using std::make_shared;
using std::shared_ptr;
using std::string;
using std::to_string;
} // End namespace
#pragma pack(push, 1) #pragma pack(push, 1)
@@ -65,184 +71,187 @@ struct BITMAP_QUAD {
#define BITMAP_MAGIC 19778 #define BITMAP_MAGIC 19778
uint16_t SwapBytes(uint16_t value) {
return ((value & 0xFF00) >> 8) | ((value & 0x00FF) << 8);
}
uint32_t SwapBytes(uint32_t value) {
return ((value & 0xFF000000) >> 24) | ((value & 0x00FF0000) >> 8) | ((value & 0x0000FF00) << 8)
| ((value & 0x000000FF) << 24);
}
void PrintBMPHeader(BITMAP_HEADER header) { void PrintBMPHeader(BITMAP_HEADER header) {
printf("Header\n"); printf("Header\n");
printf("Type: %X\nSize: %X\nReserved1: %X\nReserved2: %X\nOffset:%X\n", printf("Type: %X\nSize: %X\nReserved1: %X\nReserved2: %X\nOffset:%X\n", header.type, header.size, header.reserved1,
header.type, header.reserved2, header.offset);
header.size,
header.reserved1,
header.reserved2,
header.offset);
} }
void PrintBMPInfo(BITMAP_INFO info) { void PrintBMPInfo(BITMAP_INFO info) {
printf("Info\n"); printf("Info\n");
printf("Size: %X\nWidth: %X\nHeight:%X\n", info.size, info.width, info.height); printf("Size: %X\nWidth: %X\nHeight:%X\n", info.size, info.width, info.height);
printf("Planes: %X\nBitCount: %X\nCompression: %X\n", info.planes, info.bitCount, info.compression); printf("Planes: %X\nBitCount: %X\nCompression: %X\n", info.planes, info.bitCount, info.compression);
printf( printf("SizeImage: %X\nXPelsPerMeter: %X\nYPelsPerMeter: %X\n", info.sizeImage, info.xPelsPerMeter,
"SizeImage: %X\nXPelsPerMeter: %X\nYPelsPerMeter: %X\n", info.sizeImage, info.xPelsPerMeter, info.yPelsPerMeter); info.yPelsPerMeter);
printf("ClrUsed: %X\nClrImportant: %X\n", info.clrUsed, info.clrImportant); printf("ClrUsed: %X\nClrImportant: %X\n", info.clrUsed, info.clrImportant);
} }
TextureImage* LoadBMP(const char* fn) { BitmapImage::~BitmapImage() {}
// If anything is not perfect return NULL after cleaning up our mess
FILE* f = NULL; // A pointer to our file structure shared_ptr<BitmapImage> BitmapImage::FromFile(string filename) {
const string method_name = "OpenArena::BitmapImage::FromFile(string) ";
// TODO: Switch to fstream later.
FILE* file = nullptr;
// If our filename is null Logger::LogDebug("In " + method_name);
if (!fn) {
return NULL; // If anything is not perfect return null after cleaning up our mess.
// If our filename is empty return null.
if (filename.empty()) {
Logger::LogError(method_name + "filename is empty");
return nullptr;
} }
Logger::LogDebug(method_name + "filename is " + filename);
// TODO: If our filename doesn't exist return null.
// Try to open our file and if successfull... // Try to open our file and if successfull...
fopen_s(&file, filename.c_str(), "rb");
f = fopen(fn, "rb"); if (file == nullptr) {
if (f) { Logger::LogError(method_name + "unable to open file " + filename);
BITMAP_HEADER bmpHeader; return nullptr;
BITMAP_INFO bmpInfo;
BITMAP_QUAD* bmpPallette = NULL;
uint32_t palletteEntries = 0;
fread(&bmpHeader, sizeof(bmpHeader), 1, f);
uint8_t t[2] = {1, 0};
if (*((short*)t) != 1) {
// If big endian reorder bytes
bmpHeader.type = ((bmpHeader.type & 0xff00) >> 8) | ((bmpHeader.type & 0x00ff) << 8);
bmpHeader.size = (bmpHeader.size & 0xff000000) >> 24 | (bmpHeader.size & 0x00ff0000) >> 8
| (bmpHeader.size & 0x0000ff00) << 8 | (bmpHeader.size & 0x000000ff) << 24;
bmpHeader.reserved1 = ((bmpHeader.reserved1 & 0xff00) >> 8) | ((bmpHeader.reserved1 & 0x00ff) << 8);
bmpHeader.reserved2 = ((bmpHeader.reserved2 & 0xff00) >> 8) | ((bmpHeader.reserved2 & 0x00ff) << 8);
bmpHeader.offset = (bmpHeader.offset & 0xff000000) >> 24 | (bmpHeader.offset & 0x00ff0000) >> 8
| (bmpHeader.offset & 0x0000ff00) << 8 | (bmpHeader.offset & 0x000000ff) << 24;
}
fread(&bmpInfo, sizeof(bmpInfo), 1, f);
if (*((short*)t) != 1) {
// If big endian reorder bytes
bmpInfo.size = (bmpInfo.size & 0xff000000) >> 24 | (bmpInfo.size & 0x00ff0000) >> 8
| (bmpInfo.size & 0x0000ff00) << 8 | (bmpInfo.size & 0x000000ff) << 24;
bmpInfo.width = (bmpInfo.width & 0xff000000) >> 24 | (bmpInfo.width & 0x00ff0000) >> 8
| (bmpInfo.width & 0x0000ff00) << 8 | (bmpInfo.width & 0x000000ff) << 24;
bmpInfo.height = (bmpInfo.height & 0xff000000) >> 24 | (bmpInfo.height & 0x00ff0000) >> 8
| (bmpInfo.height & 0x0000ff00) << 8 | (bmpInfo.height & 0x000000ff) << 24;
bmpInfo.planes = ((bmpInfo.planes & 0xff00) >> 8) | ((bmpInfo.planes & 0x00ff) << 8);
bmpInfo.bitCount = ((bmpInfo.bitCount & 0xff00) >> 8) | ((bmpInfo.bitCount & 0x00ff) << 8);
bmpInfo.compression = (bmpInfo.compression & 0xff000000) >> 24 | (bmpInfo.compression & 0x00ff0000) >> 8
| (bmpInfo.compression & 0x0000ff00) << 8 | (bmpInfo.compression & 0x000000ff) << 24;
bmpInfo.sizeImage = (bmpInfo.sizeImage & 0xff000000) >> 24 | (bmpInfo.sizeImage & 0x00ff0000) >> 8
| (bmpInfo.sizeImage & 0x0000ff00) << 8 | (bmpInfo.sizeImage & 0x000000ff) << 24;
bmpInfo.xPelsPerMeter = (bmpInfo.xPelsPerMeter & 0xff000000) >> 24 | (bmpInfo.xPelsPerMeter & 0x00ff0000) >> 8
| (bmpInfo.xPelsPerMeter & 0x0000ff00) << 8 | (bmpInfo.xPelsPerMeter & 0x000000ff) << 24;
bmpInfo.yPelsPerMeter = (bmpInfo.yPelsPerMeter & 0xff000000) >> 24 | (bmpInfo.yPelsPerMeter & 0x00ff0000) >> 8
| (bmpInfo.yPelsPerMeter & 0x0000ff00) << 8 | (bmpInfo.yPelsPerMeter & 0x000000ff) << 24;
bmpInfo.clrUsed = (bmpInfo.clrUsed & 0xff000000) >> 24 | (bmpInfo.clrUsed & 0x00ff0000) >> 8
| (bmpInfo.clrUsed & 0x0000ff00) << 8 | (bmpInfo.clrUsed & 0x000000ff) << 24;
bmpInfo.clrImportant = (bmpInfo.clrImportant & 0xff000000) >> 24 | (bmpInfo.clrImportant & 0x00ff0000) >> 8
| (bmpInfo.clrImportant & 0x0000ff00) << 8 | (bmpInfo.clrImportant & 0x000000ff) << 24;
}
if (bmpInfo.width < 0) {
// This needs to be abstracted somehow
#ifdef WIN32
MessageBox(NULL, "Image width is negative", "ERROR", MB_OK);
#endif
fclose(f);
return NULL;
}
if (bmpInfo.width % 4 != 0) {
// This needs to be abstracted somehow
#ifdef WIN32
MessageBox(NULL, "Image width must be a multiple of 8", "ERROR", MB_OK);
#endif
fclose(f);
return NULL;
}
if (bmpInfo.height < 0) {
// This needs to be abstracted somehow
#ifdef WIN32
MessageBox(NULL, "Image height is negative", "ERROR", MB_OK);
#endif
fclose(f);
return NULL;
}
if (bmpInfo.height % 4 != 0) {
// This needs to be abstracted somehow
#ifdef WIN32
MessageBox(NULL, "Image height must be a multiple of 8", "ERROR", MB_OK);
#endif
fclose(f);
return NULL;
}
if ((bmpInfo.bitCount != 8 && bmpInfo.bitCount != 24) || bmpInfo.compression != 0) {
// This needs to be abstracted somehow
#ifdef WIN32
MessageBox(NULL,
"Only 8 and 24 bit uncompressed windows bmp files are "
"currently supported",
"ERROR",
MB_OK);
#endif
fclose(f);
return NULL;
}
// Allocate memory for a TextureImage structure
TextureImage* tex = new TextureImage;
tex->sizeX = bmpInfo.width;
tex->sizeY = bmpInfo.height;
if (bmpInfo.bitCount >= 8) {
tex->bpp = bmpInfo.bitCount >> 3;
}
tex->type = GL_RGB;
uint32_t pixels = tex->sizeX * tex->sizeY;
uint32_t bytes = pixels * tex->bpp;
tex->data = new uint8_t[bytes];
if (bmpInfo.bitCount == 8) {
// Load the pallette
palletteEntries = bmpInfo.bitCount << 8;
bmpPallette = new BITMAP_QUAD[palletteEntries];
fread(bmpPallette, sizeof(BITMAP_QUAD), palletteEntries, f);
}
fseek(f, bmpHeader.offset, SEEK_SET);
fread(tex->data, bytes, 1, f);
if (bmpInfo.bitCount == 8) {
// Apply the pallette
uint8_t* image = tex->data;
tex->bpp = 24;
bytes = pixels * tex->bpp;
tex->data = new uint8_t[bytes];
uint32_t i;
uint32_t i2;
for (i = 0; i < pixels; i++) {
i2 = (i << 1) + 1;
// Should make sure image[i] < palletteEntries
tex->data[i2] = bmpPallette[image[i]].red;
tex->data[i2 + 1] = bmpPallette[image[i]].blue;
tex->data[i2 + 2] = bmpPallette[image[i]].green;
}
delete[] image;
image = NULL;
} else if (bmpInfo.bitCount == 24) {
uint32_t i;
uint8_t t;
for (i = 0; i < bytes; i += 3) {
t = tex->data[i];
tex->data[i] = tex->data[i + 2];
tex->data[i + 2] = t;
}
}
return tex;
} }
return NULL; Logger::LogDebug(method_name + "opened file with handle " + to_string((uint64_t)file));
BITMAP_HEADER bmpHeader;
BITMAP_INFO bmpInfo;
BITMAP_QUAD* bmpPallette = nullptr;
uint32_t palletteEntries = 0;
if (fread(&bmpHeader, sizeof(bmpHeader), 1, file) != 1) {
Logger::LogError(method_name + "Failed to read bitmap header.");
fclose(file);
return nullptr;
}
// TODO: Come up with a better endianness check.
uint8_t t[2] = {1, 0};
if (*((short*)t) != 1) {
// If big endian reorder bytes.
bmpHeader.type = SwapBytes(bmpHeader.type);
bmpHeader.size = SwapBytes(bmpHeader.size);
bmpHeader.reserved1 = SwapBytes(bmpHeader.reserved1);
bmpHeader.reserved2 = SwapBytes(bmpHeader.reserved2);
bmpHeader.offset = SwapBytes(bmpHeader.offset);
}
if (fread(&bmpInfo, sizeof(bmpInfo), 1, file) != 1) {
Logger::LogError(method_name + "Unable to read BITMAP_INFO.");
fclose(file);
return nullptr;
}
if (*((short*)t) != 1) {
// If big endian reorder bytes.
bmpInfo.size = SwapBytes(bmpInfo.size);
bmpInfo.width = SwapBytes(bmpInfo.width);
bmpInfo.height = SwapBytes(bmpInfo.height);
bmpInfo.planes = SwapBytes(bmpInfo.planes);
bmpInfo.bitCount = SwapBytes(bmpInfo.bitCount);
bmpInfo.compression = SwapBytes(bmpInfo.compression);
bmpInfo.sizeImage = SwapBytes(bmpInfo.sizeImage);
bmpInfo.xPelsPerMeter = SwapBytes(bmpInfo.xPelsPerMeter);
bmpInfo.yPelsPerMeter = SwapBytes(bmpInfo.yPelsPerMeter);
bmpInfo.clrUsed = SwapBytes(bmpInfo.clrUsed);
bmpInfo.clrImportant = SwapBytes(bmpInfo.clrImportant);
}
if (bmpInfo.width < 0) {
Logger::LogError("Image width is negative.");
fclose(file);
return nullptr;
}
if (bmpInfo.width % 4 != 0) {
Logger::LogError("Image width must be a multiple of 8.");
fclose(file);
return nullptr;
}
if (bmpInfo.height < 0) {
Logger::LogError("Image height is negative.");
fclose(file);
return nullptr;
}
if (bmpInfo.height % 4 != 0) {
Logger::LogError("Image height must be a multiple of 8.");
fclose(file);
return nullptr;
}
if ((bmpInfo.bitCount != 8 && bmpInfo.bitCount != 24) || bmpInfo.compression != 0) {
Logger::LogError("Only 8 and 24 bit uncompressed windows bmp files are currently supported.");
fclose(file);
return nullptr;
}
// Allocate memory for our image data.
shared_ptr<BitmapImage> bmp = make_shared<BitmapImage>();
bmp->size_x_ = bmpInfo.width;
bmp->size_y_ = bmpInfo.height;
bmp->bpp_ = bmpInfo.bitCount;
int bytes_per_pixel = bmp->bpp_ / 8;
bmp->type_ = Type::RGB;
int num_pixels = bmp->size_x_ * bmp->size_y_;
int num_bytes = num_pixels * bytes_per_pixel;
Logger::LogDebug("allocating " + to_string(num_bytes) + " bytes for pixel data");
bmp->data_ = shared_ptr<uint8_t[]>(new uint8_t[num_bytes]);
if (bmpInfo.bitCount == 8) {
Logger::LogDebug("image has a pallette");
// Load the pallette
palletteEntries = bmpInfo.bitCount << 8;
bmpPallette = new BITMAP_QUAD[palletteEntries];
if (fread(bmpPallette, sizeof(BITMAP_QUAD), palletteEntries, file) != palletteEntries) {
Logger::LogError(method_name + "Wrong number of pallette entries read.");
fclose(file);
return nullptr;
}
}
Logger::LogDebug("Loading bitmap data from file.");
fseek(file, bmpHeader.offset, SEEK_SET);
if (fread(bmp->data_.get(), num_bytes, 1, file) != 1) {
Logger::LogError(method_name + "Failed to read the expected number of pixels from the file.");
fclose(file);
return nullptr;
}
Logger::LogDebug("Processing image data.");
if (bmpInfo.bitCount == 8) {
// Apply the pallette
shared_ptr<uint8_t[]> image = bmp->data_;
bmp->bpp_ = 24;
bytes_per_pixel = bmp->bpp_ / 8;
num_bytes = num_pixels * bytes_per_pixel;
bmp->data_ = shared_ptr<uint8_t[]>(new uint8_t[num_bytes]);
uint32_t i;
uint32_t i2;
for (i = 0; i < num_pixels; i++) {
i2 = (i << 1) + 1;
// Should make sure image[i] < palletteEntries
bmp->data_[i2] = bmpPallette[image[i]].red;
bmp->data_[i2 + 1] = bmpPallette[image[i]].blue;
bmp->data_[i2 + 2] = bmpPallette[image[i]].green;
}
image = nullptr;
} else if (bmpInfo.bitCount == 24) {
uint32_t i;
uint8_t t;
for (i = 0; i < num_bytes; i += 3) {
t = bmp->data_[i];
bmp->data_[i] = bmp->data_[i + 2];
bmp->data_[i + 2] = t;
}
}
return bmp;
} }
}; // End namespace OpenArena }; // End namespace OpenArena

34
bmp.h
View File

@@ -17,32 +17,26 @@
* Free Software Foundation, Inc., * * Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/ ***************************************************************************/
#ifndef OpenArena__bmp_h__ #ifndef OpenArena__bmp_h__
#define OpenArena__bmp_h__ #define OpenArena__bmp_h__
#if defined HAVE_CONFIG_H // clang-format off
#include "config.h" #include "config.h"
#endif #include <memory>
#include <string>
#include "image.h"
#include "texture.h" #include "texture.h"
// clang-format on
namespace OpenArena { namespace OpenArena {
/**
* \brief class BitmapImage : public ImageBase {
* Loads a bitmap (*.bmp) file and returns a pointer to a TextureImage object. public:
* virtual ~BitmapImage();
* \param filename static std::shared_ptr<BitmapImage> FromFile(std::string filename);
* The path to the file to open. };
* } // End namespace OpenArena
* \returns
* A pointer to the created TextureImage object.
*
* \remarks
* Will be replaced with an actual class soon
*
* \see
*/
TextureImage* LoadBMP(const char* Filename);
}; // End namespace OpenArena
#endif // End !defined(OpenArena__bmp_h__) #endif // End !defined(OpenArena__bmp_h__)

View File

@@ -17,29 +17,19 @@
* Free Software Foundation, Inc., * * Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/ ***************************************************************************/
#include "camera.h"
#include <OpenGL/glu.h> // clang-format off
#include "camera.h"
#include "opengl.h"
// clang-format on
namespace OpenArena { namespace OpenArena {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
Camera::Camera() { Camera::Camera() : _position(0, 0, 0), _heading(0, 0, 0), _up(0, 1, 0) {}
_position = Vec3f(0, 0, 0);
_heading = Vec3f(0, 0, -1);
_up = Vec3f(0, 1, 0);
}
void Camera::PositionCamera(double xpos, void Camera::PositionCamera(double xpos, double ypos, double zpos, double xview, double yview, double zview, double xup,
double ypos, double yup, double zup) {
double zpos,
double xview,
double yview,
double zview,
double xup,
double yup,
double zup) {
_position = Vec3f(xpos, ypos, zpos); _position = Vec3f(xpos, ypos, zpos);
_heading = Vec3f(xview - xpos, yview - ypos, zview - zpos); _heading = Vec3f(xview - xpos, yview - ypos, zview - zpos);
_up = Vec3f(xup, yup, zup).normalized(); _up = Vec3f(xup, yup, zup).normalized();
@@ -161,5 +151,4 @@ Vec3f Camera::GetForwardVector() {
void Camera::UpdateVectors() {} void Camera::UpdateVectors() {}
#pragma clang diagnostic pop
}; // End namespace OpenArena }; // End namespace OpenArena

372
camera.h
View File

@@ -17,361 +17,121 @@
* Free Software Foundation, Inc., * * Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/ ***************************************************************************/
#ifndef OpenArena__camera_h__ #ifndef OpenArena__camera_h__
#define OpenArena__camera_h__ #define OpenArena__camera_h__
#if defined HAVE_CONFIG_H // clang-format off
#include "config.h" #include "config.h"
#endif
#include <cmath> #include <cmath>
#ifdef WIN32
#include <windows.h> //Currently used for mouse stuff this should be replaced by oa_input
#endif
#include "window.h" #include "window.h"
// clang-format on
namespace OpenArena { namespace OpenArena {
/*! /// @brief The Camera class represents a camera or view in 3-dimensional space.
* \brief ///
* The Camera class represents a camera or view in 3-dimensional space. /// The Camera class maintains location, view, and orientation (up view) vectors.
* /// The Camera can be moved and rotated in any direction. It includes a wrapper,
* The Camera class maintains location, view, and orientation (up view) vectors. /// Look(), for gluLookAt.
* The Camera can be moved and rotated in any direction. It includes a wrapper,
* Look(), for gluLookAt.
*
* \remarks
*
* \see
*/
class Camera { class Camera {
public: public:
/*! /// @brief Creates a new Camera object.
* \brief /// Creates a new Camera object located at the origin, pointing at the negative
* Creates a new Camera object. /// z-axis with up being the positive y-axis.
* Camera();
* Creates a new Camera object located at the origin, pointing at the negative
* z-axis with up being the positive y-axis.
*
*/
Camera(); // Default Constructor
// Camera(const Camera&); //Copy Constructor // Camera(const Camera&); //Copy Constructor
/*! /// @brief Returns this Camera's position.
* \brief /// @return This Camera's position as a Vec3d vector
* Returns this Camera's position.
*
* \returns
* This Camera's position as a Vec3d vector.
*
* Returns this Camera's position.
*
*/
Vec3f Position(); Vec3f Position();
/*! /// @brief Returns the view vector of this camera.
* \brief /// @return The view vector of this camera.
* Returns the view vector of this camera.
*
* \returns
* The view vector of this camera.
*
* \remarks
*
* \see
*/
Vec3d View(); Vec3d View();
/*! /// @brief Returns a vector pointing up with respect to the view.
* \brief /// @return A vector pointing up with respect to the view.
* Returns a vector pointing up with respect to the view.
*
* \returns
* A vector pointing up with respect to the view.
*
* \remarks
*
* \see
*/
Vec3d UpVector(); Vec3d UpVector();
/*! /// @brief Returns this Camera's strafe vector.
* \brief /// The strafe axis is an axis perpendicular to both the up vector and the view vector.
* Returns this Camera's strafe vector. /// @return This Camera's strafe vector.
*
* The strafe axis is an axis perpendicular to both the up vector and the view
* vector.
*
* \returns
* This Camera's strafe vector.
*
* \remarks
*
* \see
*/
Vec3d Strafe(); Vec3d Strafe();
/*! /// @brief Relocates and reorients this Camera.
* \brief /// @param xpos The x-cooridnate of the new position vector.
* Relocates and reorients this Camera. /// @param ypos The y-coordinate of the new position vector.
* /// @param zpos The z-coordinate of the new position vector.
* \param xpos /// @param xview The x-coordinate of the new view vector.
* The x-coordinate of the new position vector. /// @param yview The y-coordiante of the new view vector.
* /// @param zview The z-cooridnate of the new view vector.
* \param ypos /// @param xup The x-coordinate of the new up vector.
* The y-coordinate of the new position vector. /// @param yup The y-coordinate of the new up vector.
* /// @param zup The z-coordinate of the new up vector.
* \param zpos void PositionCamera(double xpos, double ypos, double zpos, double xview, double yview, double zview, double xup,
* The z-coordinate of the new position vector. double yup, double zup);
*
* \param xview
* The x-coordinate of the new view vector.
*
* \param yview
* The y-coordinate of the new view vector.
*
* \param zview
* The z-coordinate of the new view vector.
*
* \param xup
* The x-coordinate of the new up vector.
*
* \param yup
* The y-coordinate of the new up vector.
*
* \param zup
* The z-coordinate of the new up vector.
*
* \remarks
*
* \see
*/
void PositionCamera(double xpos,
double ypos,
double zpos,
double xview,
double yview,
double zview,
double xup,
double yup,
double zup);
/*! /// @brief Relocates and reorients this Camera.
* \brief /// @param pos The new position vector.
* Relocates and reorients this Camera. /// @param view The new view vector.
* /// @param up The new up vector.
* \param pos
* The new position vector.
*
* \param view
* The new view vector.
*
* \param up
* The new up vector.
*
* \remarks
*
* \see
*/
void PositionCamera(Vec3d pos, Vec3d view, Vec3d up); void PositionCamera(Vec3d pos, Vec3d view, Vec3d up);
/*! /// @brief Rotates the camera a given amount around a given axis.
* \brief /// @param angle The number of degrees to rotate. Is this actually degrees not radians?
* Rotates the camera a given ammount around a given axis. /// @param axis A vector representing the axis to rotate around.
* /// This method passes the arguments to glRotatef().
* \param angle
* The number of degrees to rotate.
*
* \param axis
* A vector representing the axis to rotate around.
*
* This method passes the arguments to glRotatef()
* \remarks
*
* \see
*/
void RotateView(double angle, Vec3d axis); void RotateView(double angle, Vec3d axis);
/*! /// @brief Rotates the camera a given amount around a given axis.
* \brief /// @param angle The number of degrees to rotate.
* Rotates the camera a given ammount around a given axis. /// @param X The x-component of the vector representing the axis to rotate around.
* /// @param Y The y-component of the vector representing the axis to rotate around.
* \param angle /// @param Z The z-component of the vector representing the axis to rotate around.
* The number of degrees to rotate. /// The vector should be normalized as the values get passed directly to glRotatef().
*
* \param X
* The x component of the vector representing the axis to rotate around
*
* \param Y
* The y component of the vector representing the axis to rotate around
*
* \param Z
* The z component of the vector representing the axis to rotate around
*
* \remarks
* The vector should be normalized as the values get passed directly to
* glRotatef().
*
* \see
*/
void RotateView(double angle, double X, double Y, double Z); void RotateView(double angle, double X, double Y, double Z);
/*! /// @brief Updates the view and up vectors based on mouse movement.
* \brief /// @param window The Window used to get the mouse coordinates.
* Updates the view and up vectors based on mouse movement. /// This will be removed in favor of some sort of event trigger.
*
* \param window
* The Window used to get the mouse coordinates.
*
* \remarks
* This will be removed in favor of some sort of event trigger.
*
* \see
*/
void SetViewByMouse(Window window); void SetViewByMouse(Window window);
/*! /// @brief Moves the camera along its strafe axis a given distance.
* \brief /// @param speed The distance to move.
* Moves the camera along its strafe axis a given distance.
*
* \param speed
* The distance to move.
*
* \remarks
*
* \see
*/
void StrafeCamera(double speed); void StrafeCamera(double speed);
// Purpose: // Purpose:
// Moves the camera along it's strafe vector speed units. // Moves the camera along it's strafe vector speed units.
/*! /// @brief Moves the camera along its view vector a given number of units.
* \brief /// @param speed The distance to move the camera.
* Moves the camera along its view vector a given number of units.
*
* \param speed
* The distance to move the camera.
*
* \remarks
*
* \see
*/
void MoveCamera(double speed); void MoveCamera(double speed);
/*! /// @brief Recalculates the strafe vector.
* \brief
* Recalculates the strafe vector.
*
* \remarks
*
* \see
*/
void Update(); void Update();
/*! /// @brief Calls gluLookAt to tell OpenGL where to render from.
* \brief /// Uses the position, view, and up vectors.
* Calls gluLookAt to tell OpenGL where to render from.
*
* \remarks
* Uses the position, view, and up vectors.
*
* \see
*/
void Look(); void Look();
/*!
* \brief
* Write brief comment for RotateHorizontal here.
*
* \param angle
* Description of parameter angle.
*
* \throws <exception class>
* Description of criteria for throwing this exception.
*
* Write detailed description for RotateHorizontal here.
*
* \remarks
* Write remarks for RotateHorizontal here.
*
* \see
* Separate items with the '|' character.
*/
void RotateHorizontal(float angle); void RotateHorizontal(float angle);
/*!
* \brief
* Write brief comment for RotateVertical here.
*
* \param angle
* Description of parameter angle.
*
* \throws <exception class>
* Description of criteria for throwing this exception.
*
* Write detailed description for RotateVertical here.
*
* \remarks
* Write remarks for RotateVertical here.
*
* \see
* Separate items with the '|' character.
*/
void RotateVertical(float angle); void RotateVertical(float angle);
private: private:
/*!
* \brief
* Write brief comment for GetUpVector here.
*
* \returns
* Write description of return value here.
*
* \throws <exception class>
* Description of criteria for throwing this exception.
*
* Write detailed description for GetUpVector here.
*
* \remarks
* Write remarks for GetUpVector here.
*
* \see
* Separate items with the '|' character.
*/
Vec3f GetUpVector(); Vec3f GetUpVector();
/*! /// @brief Returns a unit vector pointing to the immediate right of the current view.
* \brief /// @return A unit vector pointing to the immediate right of the current view.
* Returns a unit vector pointing to the immediate right of the current view. /// Returns a unit vector pointing to the immediate right of the current view. This is the direction of a positive
* /// strafe movement.
*
* \returns
* A unit vector pointing to the immediate right of the current view.
*
* Returns a unit vector pointing to the immediate right of the current view.
* This is the direction of a positive strafe movement.
*
* \remarks
*
* \see
*/
Vec3f GetRightVector(); Vec3f GetRightVector();
/*! /// @brief Returns a unit vector pointing directly into the current view.
* \brief /// @return A unit vector pointing directly into the current view.
* Returns a unit vector pointing directly into the current view. /// Returns a unit vector pointing directly into the current view. This is the direction of positive movement.
*
* \returns
* A unit vector pointing directly into the current view.
*
* Returns a unit vector pointing directly into the current view. This is the
* direction of positive movement.
*
* \remarks
*
* \see
*/
Vec3f GetForwardVector(); Vec3f GetForwardVector();
void UpdateVectors(); void UpdateVectors();

42
camera_test.cpp Normal file
View File

@@ -0,0 +1,42 @@
/***************************************************************************
* Copyright (C) 2001-2023 by Tom Hicks *
* headhunter3@gmail.com *
* *
* 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 <iostream>
#include "tinytest.h"
namespace {
using std::cout;
using TinyTest::TestResults;
} // namespace
TestResults test_something() {
return TestResults().Pass();
}
int main(int argc, char* argv[]) {
TestResults results;
results += test_something();
PrintResults(cout, results);
return results.Failed() + results.Errors();
}

20
PluginManager.cpp → config.h Executable file → Normal file
View File

@@ -17,21 +17,11 @@
* Free Software Foundation, Inc., * * Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/ ***************************************************************************/
#include "PluginManager.h"
#include "NullVideoPlugin.h" #ifndef OpenArena__config_h__
#define OpenArena__config_h__
namespace OpenArena { #define USE_OPENGL
PluginManager::PluginManager(void) {} #define USE_WGL
PluginManager::~PluginManager(void) {} #endif // End !defined(OpenArena__config_h__)
list<Plugin*> PluginManager::GetPluginsOfType(Plugin::Type type) {
return list<Plugin*>();
}
VideoPlugin* PluginManager::GetDefaultVideoPlugin(void) {
return new NullVideoPlugin();
}
} // End namespace OpenArena

70
console_logger.cpp Normal file
View File

@@ -0,0 +1,70 @@
/***************************************************************************
* Copyright (C) 2001-2023 by Tom Hicks *
* headhunter3@gmail.com *
* *
* 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. *
***************************************************************************/
// clang-format off
#include "console_logger.h"
#include <iostream>
#include <string>
// clang-format on
namespace OpenArena {
namespace {
using std::cout;
using std::endl;
using std::string;
} // End namespace
ConsoleLogger::ConsoleLogger() {}
ConsoleLogger::~ConsoleLogger() {}
void ConsoleLogger::LogMessage(const MessageType& type, const std::string& message) const {
cout << "[" << GetTitle(type) << "] " << message << endl;
}
void ConsoleLogger::LogError(const MessageType& type, const std::exception& ex) const {
cout << "[" << GetTitle(type) << "] caught exception: " << ex.what() << endl;
}
void ConsoleLogger::LogError(const MessageType& type, const std::string& message, const std::exception& ex) const {
cout << "[" << GetTitle(type) << "] " << message << " with caught exception " << ex.what() << endl;
}
string ConsoleLogger::GetTitle(const MessageType& type) const {
switch (type) {
case Debug:
return "Debug";
case Error:
return "Error";
case Wtf:
return "Wtf";
case Info:
return "Info";
case Warning:
return "Warning";
case Verbose:
return "Verbose";
default:
return "Unclassified";
}
}
} // End namespace OpenArena

58
Plugin.h → console_logger.h Executable file → Normal file
View File

@@ -17,52 +17,26 @@
* Free Software Foundation, Inc., * * Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/ ***************************************************************************/
#ifndef OpenArena__Plugin_h__
#define OpenArena__Plugin_h__
#if defined HAVE_CONFIG_H #ifndef OpenArena__console_logger_h__
#include "config.h" #define OpenArena__console_logger_h__
#endif // clang-format off
#include "Logger.h"
// clang-format on
namespace OpenArena { namespace OpenArena {
/*! class ConsoleLogger : public Logger {
* \brief
* Write brief comment for Plugin here.
*
* Write detailed description for Plugin here.
*
* \remarks
* Write remarks for Plugin here.
*
* \see
* Separate items with the '|' character.
*/
class Plugin {
public: public:
/*! ConsoleLogger();
* \brief virtual ~ConsoleLogger();
* Write brief comment for ~Plugin here. virtual void LogMessage(const MessageType& type, const std::string& message) const;
* virtual void LogError(const MessageType& type, const std::exception& ex) const;
* \throws <exception class> virtual void LogError(const MessageType& type, const std::string& message, const std::exception& ex) const;
* Description of criteria for throwing this exception.
*
* Write detailed description for ~Plugin here.
*
* \remarks
* Write remarks for ~Plugin here.
*
* \see
* Separate items with the '|' character.
*/
virtual ~Plugin(void) {}
/*! private:
* \brief std::string GetTitle(const MessageType& type) const;
* Write brief comment for InputPlugin here.
*/
enum Type { VideoPlugin, AudioPlugin, InputPlugin };
}; };
} // namespace OpenArena
} // End namespace OpenArena #endif // End !defined(OpenArena__console_logger_h__)
#endif // End !defined(OpenArena__Plugin_h__)

42
console_logger_test.cpp Normal file
View File

@@ -0,0 +1,42 @@
/***************************************************************************
* Copyright (C) 2001-2023 by Tom Hicks *
* headhunter3@gmail.com *
* *
* 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 <iostream>
#include "tinytest.h"
namespace {
using std::cout;
using TinyTest::TestResults;
} // namespace
TestResults test_something() {
return TestResults().Pass();
}
int main(int argc, char* argv[]) {
TestResults results;
results += test_something();
PrintResults(cout, results);
return results.Failed() + results.Errors();
}

View File

@@ -17,15 +17,21 @@
* Free Software Foundation, Inc., * * Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/ ***************************************************************************/
#include "ctrls.h"
// clang-format off
#include "ctrls.h"
#include "strmanip.h" #include "strmanip.h"
using std::endl; // clang-foramt on
using std::ostream;
using std::string;
namespace OpenArena { namespace OpenArena {
namespace {
using std::endl;
using std::ostream;
using std::string;
} // End namespace
void ControlScheme::LoadDefaultControlScheme() { void ControlScheme::LoadDefaultControlScheme() {
UnBindAll();
Bind(OpenArena::KEY_LBUTTON, ACTION_FORWARD); Bind(OpenArena::KEY_LBUTTON, ACTION_FORWARD);
Bind(OpenArena::KEY_RBUTTON, ACTION_BACKWARD); Bind(OpenArena::KEY_RBUTTON, ACTION_BACKWARD);
Bind(OpenArena::KEY_LEFT, ACTION_LOOKLEFT); Bind(OpenArena::KEY_LEFT, ACTION_LOOKLEFT);
@@ -184,4 +190,12 @@ bool ControlScheme::IsBound(OpenArena::Keys key, Action action) {
return false; return false;
} }
ControlScheme::Action ControlScheme::GetAction(OpenArena::Keys key) {
return keyActions[key];
}
ControlScheme::ControlScheme(){
UnBindAll();
}
} // End namespace OpenArena } // End namespace OpenArena

10
ctrls.h
View File

@@ -17,17 +17,17 @@
* Free Software Foundation, Inc., * * Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/ ***************************************************************************/
#ifndef OpenArena__ctrls_h__ #ifndef OpenArena__ctrls_h__
#define OpenArena__ctrls_h__ #define OpenArena__ctrls_h__
// clang-format off
#if defined HAVE_CONFIG_H
#include "config.h" #include "config.h"
#endif
#include <iostream> #include <iostream>
#include <string> #include <string>
#include "keys.h" #include "keys.h"
// clang-format on
namespace OpenArena { namespace OpenArena {
class ControlScheme { class ControlScheme {
public: public:
@@ -57,11 +57,13 @@ class ControlScheme {
NUM_ACTIONS NUM_ACTIONS
}; };
ControlScheme();
void LoadDefaultControlScheme(); void LoadDefaultControlScheme();
void UnBindAll(); void UnBindAll();
void UnBind(OpenArena::Keys key); void UnBind(OpenArena::Keys key);
void Bind(OpenArena::Keys key, Action action); void Bind(OpenArena::Keys key, Action action);
void WriteToStream(std::ostream& output); void WriteToStream(std::ostream& output);
Action GetAction(OpenArena::Keys key);
static Action GetAction(const char* actionName); static Action GetAction(const char* actionName);
static const char* GetActionName(Action action); static const char* GetActionName(Action action);
bool IsBound(OpenArena::Keys key, Action action); bool IsBound(OpenArena::Keys key, Action action);

17
NullVideoPlugin.cpp → geometry.cpp Executable file → Normal file
View File

@@ -17,17 +17,16 @@
* Free Software Foundation, Inc., * * Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/ ***************************************************************************/
#include "NullVideoPlugin.h"
// clang-format off
#include "geometry.h"
#include "myglTexture.h"
// clang-format on
namespace OpenArena { namespace OpenArena {
NullVideoPlugin::NullVideoPlugin(void) {} // public OpenArena::Triangle::Triangle(void)
Triangle::Triangle() : texture(kUnknownTexture) {}
NullVideoPlugin::~NullVideoPlugin(void) {}
OpenArena::Window* NullVideoPlugin::CreateNewWindow(
uint32_t width, uint32_t height, uint32_t bpp, bool fullscreen, const char* title) {
return new OpenArena::Window();
}
} // End namespace OpenArena } // End namespace OpenArena

View File

@@ -17,16 +17,16 @@
* Free Software Foundation, Inc., * * Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/ ***************************************************************************/
#ifndef OpenArena__geometry_h__ #ifndef OpenArena__geometry_h__
#define OpenArena__geometry_h__ #define OpenArena__geometry_h__
// clang-format off
#if defined HAVE_CONFIG_H
#include "config.h" #include "config.h"
#endif
#include "myglTexture.h" #include "myglTexture.h"
#include "vector.h" #include "vector.h"
// clang-format on
namespace OpenArena { namespace OpenArena {
class Vertex { class Vertex {
public: public:
@@ -34,25 +34,12 @@ class Vertex {
Vec2f textureCoordinates; Vec2f textureCoordinates;
}; };
/*!
* \brief
* Write brief comment for Triangle here.
*
* Write detailed description for Triangle here.
*
* \remarks
* Write remarks for Triangle here.
*
* \see
* Separate items with the '|' character.
*/
class Triangle { class Triangle {
public: public:
Texture texture; Triangle();
Texture& texture;
uint32_t texID; uint32_t texID;
Vertex vertecies[3]; Vertex vertecies[3];
// Vec3f vertecies[3];
// Vec2f texCoords[3];
Vec3f normal; Vec3f normal;
}; };

View File

@@ -26,3 +26,23 @@
// description // description
// //
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
/***************************************************************************
* Copyright (C) 2001-2023 by Tom Hicks *
* headhunter3@gmail.com *
* *
* 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. *
***************************************************************************/

BIN
image.cpp Normal file

Binary file not shown.

172
image.h
View File

@@ -17,162 +17,54 @@
* Free Software Foundation, Inc., * * Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/ ***************************************************************************/
#ifndef OpenArena__image_h__ #ifndef OpenArena__image_h__
#define OpenArena__image_h__ #define OpenArena__image_h__
// clang-format off
#include <cstdint>
#if defined HAVE_CONFIG_H
#include "config.h" #include "config.h"
#endif #include <cstdint>
#include <memory>
#include "texture.h"
// clang-format on
namespace OpenArena { namespace OpenArena {
/*!
* \brief class ImageBase {
* Write brief comment for Image here. public:
* enum Type { Unknown, RGB, RGBA };
* Write detailed description for Image here.
* ImageBase();
* \remarks virtual ~ImageBase();
* Write remarks for Image here. virtual std::shared_ptr<uint8_t[]> GetImageData() const;
* virtual uint32_t GetBitsPerPixel() const;
* \see virtual uint32_t GetBytesPerPixel() const;
* Separate items with the '|' character. virtual uint32_t GetWidth() const;
*/ virtual uint32_t GetHeight() const;
virtual ImageBase::Type GetType() const;
virtual TextureImage* ToTextureImage() const;
std::shared_ptr<uint8_t[]> data_;
uint32_t bpp_;
uint32_t size_x_;
uint32_t size_y_;
Type type_;
private:
};
class Image { class Image {
public: public:
// RGB should equal GL_RGB; // RGB should equal GL_RGB;
enum Type { Type_RGB }; enum Type { Type_RGB, Type_RGBA };
/*!
* \brief
* Write brief comment for GetImageData here.
*
* \returns
* Write description of return value here.
*
* \throws <exception class>
* Description of criteria for throwing this exception.
*
* Write detailed description for GetImageData here.
*
* \remarks
* Write remarks for GetImageData here.
*
* \see
* Separate items with the '|' character.
*/
virtual uint8_t* GetImageData() const = 0; virtual uint8_t* GetImageData() const = 0;
/*!
* \brief
* Write brief comment for GetBitsPerPixel here.
*
* \returns
* Write description of return value here.
*
* \throws <exception class>
* Description of criteria for throwing this exception.
*
* Write detailed description for GetBitsPerPixel here.
*
* \remarks
* Write remarks for GetBitsPerPixel here.
*
* \see
* Separate items with the '|' character.
*/
virtual uint32_t GetBitsPerPixel() const = 0; virtual uint32_t GetBitsPerPixel() const = 0;
/*!
* \brief
* Write brief comment for GetBytesPerPixel here.
*
* \returns
* Write description of return value here.
*
* \throws <exception class>
* Description of criteria for throwing this exception.
*
* Write detailed description for GetBytesPerPixel here.
*
* \remarks
* Write remarks for GetBytesPerPixel here.
*
* \see
* Separate items with the '|' character.
*/
virtual uint32_t GetBytesPerPixel() const = 0; virtual uint32_t GetBytesPerPixel() const = 0;
/*!
* \brief
* Write brief comment for GetWidth here.
*
* \returns
* Write description of return value here.
*
* \throws <exception class>
* Description of criteria for throwing this exception.
*
* Write detailed description for GetWidth here.
*
* \remarks
* Write remarks for GetWidth here.
*
* \see
* Separate items with the '|' character.
*/
virtual uint32_t GetWidth() const = 0; virtual uint32_t GetWidth() const = 0;
/*!
* \brief
* Write brief comment for GetHeight here.
*
* \returns
* Write description of return value here.
*
* \throws <exception class>
* Description of criteria for throwing this exception.
*
* Write detailed description for GetHeight here.
*
* \remarks
* Write remarks for GetHeight here.
*
* \see
* Separate items with the '|' character.
*/
virtual uint32_t GetHeight() const = 0; virtual uint32_t GetHeight() const = 0;
/*!
* \brief
* Write brief comment for GetType here.
*
* \returns
* Write description of return value here.
*
* \throws <exception class>
* Description of criteria for throwing this exception.
*
* Write detailed description for GetType here.
*
* \remarks
* Write remarks for GetType here.
*
* \see
* Separate items with the '|' character.
*/
virtual Image::Type GetType() const = 0; virtual Image::Type GetType() const = 0;
/*!
* \brief
* Write brief comment for ~Image here.
*
* \throws <exception class>
* Description of criteria for throwing this exception.
*
* Write detailed description for ~Image here.
*
* \remarks
* Write remarks for ~Image here.
*
* \see
* Separate items with the '|' character.
*/
virtual ~Image(void) {} virtual ~Image(void) {}
}; };
} // End namespace OpenArena } // End namespace OpenArena

View File

@@ -17,9 +17,11 @@
* Free Software Foundation, Inc., * * Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/ ***************************************************************************/
#include "keys.h"
// clang-format off
#include "keys.h"
#include <string> #include <string>
// clang-format on
using std::string; using std::string;

79
keys.h
View File

@@ -17,26 +17,15 @@
* Free Software Foundation, Inc., * * Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/ ***************************************************************************/
#ifndef OpenArena__keys_h__ #ifndef OpenArena__keys_h__
#define OpenArena__keys_h__ #define OpenArena__keys_h__
// clang-format off
#if defined HAVE_CONFIG_H
#include "config.h" #include "config.h"
#endif
// clang-format on
namespace OpenArena { namespace OpenArena {
/*!
* \brief
* Write brief comment for Keys here.
*
* Write detailed description for Keys here.
*
* \remarks
* Write remarks for Keys here.
*
* \see
* Separate items with the '|' character.
*/
enum Keys { enum Keys {
KEY_UNKNOWN = 0, KEY_UNKNOWN = 0,
KEY_BUTTON0, KEY_BUTTON0,
@@ -149,69 +138,9 @@ enum Keys {
KEY_OPTION KEY_OPTION
}; };
/*!
* \brief
* Write brief comment for KEY_LBUTTON here.
*
* Write detailed description for KEY_LBUTTON here.
*
* \remarks
* Write remarks for KEY_LBUTTON here.
*
* \see
* Separate items with the '|' character.
*/
const Keys KEY_LBUTTON = KEY_BUTTON0; const Keys KEY_LBUTTON = KEY_BUTTON0;
/*!
* \brief
* Write brief comment for KEY_RBUTTON here.
*
* Write detailed description for KEY_RBUTTON here.
*
* \remarks
* Write remarks for KEY_RBUTTON here.
*
* \see
* Separate items with the '|' character.
*/
const Keys KEY_RBUTTON = KEY_BUTTON1; const Keys KEY_RBUTTON = KEY_BUTTON1;
/*!
* \brief
* Write brief comment for KEY_MBUTTON here.
*
* Write detailed description for KEY_MBUTTON here.
*
* \remarks
* Write remarks for KEY_MBUTTON here.
*
* \see
* Separate items with the '|' character.
*/
const Keys KEY_MBUTTON = KEY_BUTTON2; const Keys KEY_MBUTTON = KEY_BUTTON2;
/*!
* \brief
* Write brief comment for KeyToASCII here.
*
* \param key
* Description of parameter key.
*
* \param shift
* Description of parameter shift.
*
* \returns
* Write description of return value here.
*
* \throws <exception class>
* Description of criteria for throwing this exception.
*
* Write detailed description for KeyToASCII here.
*
* \remarks
* Write remarks for KeyToASCII here.
*
* \see
* Separate items with the '|' character.
*/
char KeyToASCII(Keys key, bool shift); char KeyToASCII(Keys key, bool shift);
const char* GetKeyName(Keys key); const char* GetKeyName(Keys key);
OpenArena::Keys GetKey(const char* keyName); OpenArena::Keys GetKey(const char* keyName);

254
level.cpp
View File

@@ -17,50 +17,46 @@
* Free Software Foundation, Inc., * * Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/ ***************************************************************************/
#include "level.h"
// clang-format off
#include "level.h"
#include <sstream>
#include <vector>
#include "logger.h"
#include "version.h" #include "version.h"
#pragma clang diagnostic push // clang-format on
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
#ifdef WIN32 namespace {
#pragma warning(disable : 4996) // using std::cout;
#endif using std::endl;
#pragma clang diagnostic pop using std::ifstream;
using namespace std; using std::ofstream;
using std::ostringstream;
using std::string;
using std::to_string;
using std::vector;
} // End namespace
namespace OpenArena { namespace OpenArena {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
Level::Level(EventManager* eventManager) {
_eventManager = eventManager;
_window = NULL;
textureNames = NULL;
numTextures = 0;
// set consoleHistory
Level::Level(EventManager* eventManager)
: _eventManager(eventManager),
_window(nullptr),
showConsole(false),
showFPS(false),
defaultPlayer(nullptr),
numTextures(0),
nextLevel("intro.map"),
gamedir("oa/"),
sound(true),
numTriangles(0),
mouseSpeed(5),
turnSpeed(1.0f),
mlook(true) {
screen.SetName(OPENARENA_VERSION); screen.SetName(OPENARENA_VERSION);
showFPS = false;
showConsole = false;
nextLevel = "intro.map";
gamedir = "oa/";
sound = true;
defaultPlayer = new Player; defaultPlayer = new Player;
numTriangles = 0;
triangles = NULL;
/*
for(int x=0; x<4; x++)
LightAmbient[x] = 5;
*/
// Player Stuff
mouseSpeed = 5;
turnSpeed = 1.0f;
moveSpeed = 0.2f;
mlook = true;
} }
Level::~Level() { Level::~Level() {
@@ -71,11 +67,11 @@ Level::~Level() {
} }
bool Level::LoadMap(string mapname) { bool Level::LoadMap(string mapname) {
string method_name = "OpenArena::Level::LoadMap(string) ";
ifstream input; ifstream input;
string readBuffer; string readBuffer;
// players.Insert(*defaultPlayer); Logger::LogDebug(method_name + "Loading map: " + mapname);
mapname = gamedir + "maps/" + mapname; mapname = gamedir + "maps/" + mapname;
if (tolower(Right(mapname, 4)) != ".map") mapname = mapname + ".map"; if (tolower(Right(mapname, 4)) != ".map") mapname = mapname + ".map";
@@ -83,19 +79,13 @@ bool Level::LoadMap(string mapname) {
input.open(mapname.c_str()); input.open(mapname.c_str());
if (!input) { if (!input) {
char* tmpChar = new char[mapname.length() + 41]; string message = "Unable to load level file " + mapname + " doesn't exist.";
strcpy(tmpChar, "Unable to load level file "); Logger::LogError(method_name + message);
strcat(tmpChar, mapname.c_str()); Logger::LogDebug(method_name + "returning false.");
strcat(tmpChar, " doesn't exist.");
// This needs to be abstracted somehow
#ifdef WIN32
MessageBox(NULL, tmpChar, "ERROR", MB_OK | MB_ICONEXCLAMATION);
#endif
delete[] tmpChar;
return false; return false;
} else { } else {
ConsolePrint("map file \"" + mapname + "\" opened successfully"); Logger::LogDebug(method_name + "Map file \"" + mapname + "\" opened successfully.");
ConsolePrint("Map file \"" + mapname + "\" opened successfully.");
} }
// Gravity // Gravity
@@ -138,60 +128,53 @@ bool Level::LoadMap(string mapname) {
} }
char lpszNumTriangles[6]; char lpszNumTriangles[6];
sprintf(lpszNumTriangles, "%d", numTriangles); sprintf(lpszNumTriangles, "%d", numTriangles);
ConsolePrint(lpszNumTriangles + string(" triangles successfully read")); ConsolePrint(lpszNumTriangles + string(" triangles successfully read."));
// Number of textures; // Number of textures;
input >> readBuffer; input >> readBuffer;
numTextures = Integer(readBuffer); numTextures = Integer(readBuffer);
Logger::LogDebug("read num_textures = " + to_string(numTextures));
// Texture data // Texture data
textureNames = new string[numTextures]; textureNames = new string[numTextures];
for (unsigned int i = 0; i < numTextures; i++) { for (unsigned int i = 0; i < numTextures; i++) {
input >> textureNames[i]; input >> textureNames[i];
Logger::LogDebug("read texture name = " + textureNames[i]);
} }
LoadGLTextures(); LoadGLTextures();
Logger::LogDebug("after LoadGLTextures()");
// Copy loaded textures to the individual triangles.
for (uint32_t i = 0; i < numTriangles; i++) {
Triangle& triangle = triangles[i];
triangle.texture = *textures[triangle.texID];
}
char lpszNumTextures[6]; char lpszNumTextures[6];
sprintf(lpszNumTextures, "%d", numTextures); sprintf(lpszNumTextures, "%d", numTextures);
ConsolePrint(lpszNumTextures + string(" textures successfully read")); ConsolePrint(lpszNumTextures + string(" textures successfully read"));
Logger::LogDebug("about to read bgm from file");
// BGM // BGM
input >> bgm; input >> bgm;
// Build display list // Build display list
Logger::LogDebug(string("sound is ") + (sound ? "true" : "false"));
// Sound // Sound
if (sound) { if (sound) {
ConsolePrint("Starting sound"); ConsolePrint("Starting sound");
// This needs to be abstracted somehow
#ifdef WIN32
BASS_Init(-1, 44100, BASS_DEVICE_LEAVEVOL, g_hWnd);
BASS_Start();
BASS_CDInit(NULL, BASS_DEVICE_LEAVEVOL);
#endif
if (bgm.length() >= 4) { if (bgm.length() >= 4) {
if (toupper(bgm[0]) == 'C' && toupper(bgm[1]) == 'D' && toupper(bgm[2]) == 'A') { if (toupper(bgm[0]) == 'C' && toupper(bgm[1]) == 'D' && toupper(bgm[2]) == 'A') {
bgmCDA = Integer(bgm.substr(3, bgm.length())); bgmCDA = Integer(bgm.substr(3, bgm.length()));
// This needs to be abstracted somehow
#ifdef WIN32
BASS_CDPlay(bgmCDA, 1, 0);
#endif
} else { } else {
bgmCDA = 0; bgmCDA = 0;
string tmpstr = gamedir + "music/bgm/" + bgm; string tmpstr = gamedir + "music/bgm/" + bgm;
// This needs to be abstracted somehow // This needs to be abstracted somehow
#ifdef WIN32
bgmStream = BASS_StreamCreateFile(0, (void*)tmpstr.c_str(), 0, 0, BASS_STREAM_AUTOFREE);
BASS_StreamPlay(bgmStream, 1, BASS_SAMPLE_LOOP);
#endif
} }
} }
ConsolePrint("Sound init complete"); ConsolePrint("Sound init complete");
} else { } else {
ConsolePrint("Sound disabled"); ConsolePrint("Sound disabled");
} }
Logger::LogDebug(method_name + "returning true.");
return true; return true;
} }
@@ -210,16 +193,7 @@ void Level::SaveMap(string mapname) {
output.open(mapname.c_str()); output.open(mapname.c_str());
if (!output) { if (!output) {
char* tmpChar = new char[mapname.length() + 42]; Logger::LogError("Unable to save level file " + mapname + " already exists.");
strcpy(tmpChar, "Unable to save level file ");
strcat(tmpChar, mapname.c_str());
strcat(tmpChar, " already exists.");
// This needs to be abstracted somehow
#ifdef WIN32
MessageBox(NULL, tmpChar, "ERROR", MB_OK | MB_ICONEXCLAMATION);
#endif
delete[] tmpChar;
return; return;
} }
@@ -254,7 +228,75 @@ void Level::SaveMap(string mapname) {
output << bgm; output << bgm;
} }
string to_string(const Vertex& value) {
// Vertex {x: 12, y: 34, z: 56, u: 0.2, v: 0.4}
ostringstream os;
os << "Vertex {x: " << value.coordinates.x << ", y: " << value.coordinates.y << ", z: " << value.coordinates.z
<< ", u: " << value.textureCoordinates.x << ", v: " << value.textureCoordinates.y << "}";
return os.str();
}
string to_string(const Texture& value) {
/*
Texture {
filename: "",
id: 12,
is_loaded: true/false
},
*/
ostringstream os;
os << "Texture {filename: \"" << value.Filename() << "\", id: " << value.ID()
<< ", is_loaded: " << (value.Loaded() ? "true" : "false");
return os.str();
}
string to_string(const Vec3f& value) {
/*
Vec3f {x: 1, y: 2, z: 3}
*/
ostringstream os;
os << "Vec3f {x: " << value.x << ", y: " << value.y << ", z: " << value.z << "}";
return os.str();
}
string to_string(const Triangle& triangle) {
/*
Triangle {
normal: {x: 12, y: 34, z: 56}
tex_id: 12,
texture: {
filename: "",
id: 12,
is_loaded: true/false
},
vertecies: [
0: {x: 12, y: 34, z: 56, u: 0.2, v: 0.4},
1: {x: 12, y: 34, z: 56, u: 0.2, v: 0.4},
2: {x: 12, y: 34, z: 56, u: 0.2, v: 0.4},
]
}
*/
ostringstream os;
os << "Triangle {normal: " + to_string(triangle.normal) << ", tex_id: " << triangle.texID
<< ", texture: " << to_string(triangle.texture) << ", vertices: [";
// TODO: Make this a range based for loop after making vertices a std::array or std::vector.
for (int i = 0; i < 3; i++) {
os << std::to_string(i) << ": " << to_string(triangle.vertecies[i]) << ",";
}
os << "]}";
return os.str();
}
int num_renders = 0;
void Level::Render() { void Level::Render() {
const string method_name = "OpenArena::Level::Render() ";
static int num_renders = 0;
num_renders++;
if (num_renders > 5) {
return;
}
Logger::LogDebug(method_name + "Entered");
glPushMatrix(); glPushMatrix();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity(); glLoadIdentity();
@@ -262,15 +304,16 @@ void Level::Render() {
// Move the camera to where the player is // Move the camera to where the player is
defaultPlayer->camera.Look(); defaultPlayer->camera.Look();
Logger::LogDebug(method_name + "Rendering " + std::to_string(numTriangles) + " triangles.");
for (uint32_t i = 0; i < numTriangles; i++) { for (uint32_t i = 0; i < numTriangles; i++) {
glBindTexture(GL_TEXTURE_2D, textures[triangles[i].texID]->ID()); // Bind this triangle's texture Triangle triangle = triangles[i];
Logger::LogDebug(method_name + "Rendering a " + to_string(triangle));
glBindTexture(GL_TEXTURE_2D, triangles[i].texture.ID()); // Bind this triangle's texture
glBegin(GL_TRIANGLES); glBegin(GL_TRIANGLES);
// glNormal3f((GLfloat)triangles[i].normal.x, (GLfloat)triangles[i].normal.y,
//(GLfloat)triangles[i].normal.z);
for (uint32_t i2 = 0; i2 < 3; i2++) { for (uint32_t i2 = 0; i2 < 3; i2++) {
glTexCoord2f(triangles[i].vertecies[i2].textureCoordinates.x, triangles[i].vertecies[i2].textureCoordinates.y); glTexCoord2f(triangles[i].vertecies[i2].textureCoordinates.x, triangles[i].vertecies[i2].textureCoordinates.y);
glVertex3f((GLfloat)triangles[i].vertecies[i2].coordinates.x, glVertex3f((GLfloat)triangles[i].vertecies[i2].coordinates.x, (GLfloat)triangles[i].vertecies[i2].coordinates.y,
(GLfloat)triangles[i].vertecies[i2].coordinates.y,
(GLfloat)triangles[i].vertecies[i2].coordinates.z); (GLfloat)triangles[i].vertecies[i2].coordinates.z);
} }
glEnd(); glEnd();
@@ -366,10 +409,7 @@ void Level::UnloadMap() {
} }
// Free all map textures // Free all map textures
if (!textures.IsEmpty()) { textures.clear();
// TODOiterate over list and delete all entries
}
textures.Clear();
// Free the array of texture names // Free the array of texture names
if (textureNames) { if (textureNames) {
@@ -379,26 +419,36 @@ void Level::UnloadMap() {
} }
void Level::LoadGLTextures() { void Level::LoadGLTextures() {
if (_window != NULL) { Logger::LogDebug("In LoadGLTextures");
/* string file_name;
GLfloat light[4] = {1.0f,1.0f,1.0f,0.5f}; if (_window != nullptr) {
glLightfv(GL_LIGHT1, GL_AMBIENT, light); Logger::LogDebug("_window is not null");
glEnable(GL_LIGHT1); textures.clear();
glEnable(GL_LIGHTING);
*/
textures.Clear();
for (uint32_t i = 0; i < numTextures; i++) { for (uint32_t i = 0; i < numTextures; i++) {
Texture* texture = new Texture(); Texture* texture = new Texture();
if (!texture->Load(gamedir + "textures/" + textureNames[i])) texture->Load(DEFAULT_TEXTURE_NAME); file_name = gamedir + "textures/" + textureNames[i];
Logger::LogDebug("loading texture from " + file_name);
if (!texture->Load(file_name)) {
Logger::LogDebug("falling back to " + DEFAULT_TEXTURE_NAME);
texture->Load(DEFAULT_TEXTURE_NAME);
}
Logger::LogDebug("texture loaded");
textures[i] = texture; textures[i] = texture;
} }
if (!glFont.BuildFont((gamedir + "textures/menu/font.bmp").c_str())) glFont.BuildFont("oa/textures/menu/font.bmp"); file_name = gamedir + "textures/menu/font.bmp";
Logger::LogDebug("Loading font from " + file_name);
if (!glFont.BuildFont(file_name.c_str())) {
Logger::LogDebug("Falling back to oa/textures/menu/font.bmp");
glFont.BuildFont("oa/textures/menu/font.bmp");
}
// Load the console background image // Load the console background image
if (!menuTextures[GL_MY_TEXTURE_CONSOLEBACKGROUND].Load(gamedir + "textures/menu/con_back.tga")) { file_name = gamedir + "textures/menu/con_back.tga";
Logger::LogDebug("Loading console background from " + file_name);
if (!menuTextures[GL_MY_TEXTURE_CONSOLEBACKGROUND].Load(file_name)) {
Logger::LogDebug("Falling back to oa/textures/menu/con_back.bmp");
menuTextures[GL_MY_TEXTURE_CONSOLEBACKGROUND].Load("oa/textures/menu/con_back.bmp"); menuTextures[GL_MY_TEXTURE_CONSOLEBACKGROUND].Load("oa/textures/menu/con_back.bmp");
} }
} }
@@ -649,7 +699,6 @@ void Level::LoadConfig() {
bool Level::LoadConfig(string cfgname) { bool Level::LoadConfig(string cfgname) {
ifstream input; ifstream input;
string readBuffer; string readBuffer;
cfgname = gamedir + "config/" + cfgname; cfgname = gamedir + "config/" + cfgname;
if (tolower(Right(cfgname, 4)) != ".cfg") cfgname = cfgname + ".cfg"; if (tolower(Right(cfgname, 4)) != ".cfg") cfgname = cfgname + ".cfg";
@@ -728,6 +777,7 @@ void Level::ConsolePrint(string line) {
consoleOutput[i] = consoleOutput[i - 1]; consoleOutput[i] = consoleOutput[i - 1];
} }
consoleOutput[0] = line; consoleOutput[0] = line;
Logger::LogInfo("Console Message: " + line);
} }
void Level::SetWindow(Window* window) { void Level::SetWindow(Window* window) {
@@ -737,6 +787,4 @@ void Level::SetWindow(Window* window) {
Window* Level::GetWindow() { Window* Level::GetWindow() {
return _window; return _window;
} }
#pragma clang diagnostic pop
} // End namespace OpenArena } // End namespace OpenArena

61
level.h
View File

@@ -17,51 +17,37 @@
* Free Software Foundation, Inc., * * Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/ ***************************************************************************/
#ifndef OpenArena__level_h__ #ifndef OpenArena__level_h__
#define OpenArena__level_h__ #define OpenArena__level_h__
// clang-format off
#if defined HAVE_CONFIG_H
#include "config.h" #include "config.h"
#endif
#include <cctype> #include <cctype>
#include <cmath> #include <cmath>
#include <cstdio> //for file I/O
#include <fstream> #include <fstream>
#include <iostream> #include <iostream>
#include <string> #include <string>
#include <vector>
#if defined USE_GLX
#include <GL/gl.h>
#elif defined USE_AGL
#include <OpenGL/gl.h>
#elif defined USE_CGL
#include <OpenGL/gl.h>
#elif defined USE_WGL
#include <GL/gl.h>
#include <windows.h>
#endif
#include <cstdio> //for file I/O
#include "EventManager.h" #include "EventManager.h"
#include "bmp.h" #include "bmp.h"
#include "camera.h" #include "camera.h"
#include "geometry.h" #include "geometry.h"
#include "keys.h" #include "keys.h"
#include "list.h"
#include "mydefs.h" #include "mydefs.h"
#include "myglFont.h" #include "myglFont.h"
#include "myglTexture.h" #include "myglTexture.h"
#include "opengl.h"
#include "player.h" #include "player.h"
#include "strmanip.h" #include "strmanip.h"
#include "tga.h" #include "tga.h"
#include "vector.h" #include "vector.h"
using namespace std;
namespace OpenArena { namespace OpenArena {
const float piover180 = 0.0174532925f; const float piover180 = 0.0174532925f;
const string DEFAULT_TEXTURE_NAME = "oa/textures/default.bmp"; const std::string DEFAULT_TEXTURE_NAME = "oa/textures/default.bmp";
const unsigned int MAX_CONSOLE_LINES = 30; // The max number of lines to be displayed in the console const unsigned int MAX_CONSOLE_LINES = 30; // The max number of lines to be displayed in the console
const unsigned int MAX_CONSOLE_HISTORY_LINES = const unsigned int MAX_CONSOLE_HISTORY_LINES =
MAX_CONSOLE_LINES + 20; // The max number of console lines to store in the history MAX_CONSOLE_LINES + 20; // The max number of console lines to store in the history
@@ -74,13 +60,13 @@ class Level {
public: public:
Level(EventManager* eventManager); Level(EventManager* eventManager);
~Level(); ~Level();
bool LoadMap(string mapname); bool LoadMap(std::string mapname);
bool LoadMap(); bool LoadMap();
void SaveMap(string mapname); void SaveMap(std::string mapname);
bool LoadConfig(string cfgname); bool LoadConfig(std::string cfgname);
void LoadConfig(); void LoadConfig();
void SaveConfig(string cfgname); void SaveConfig(std::string cfgname);
void Execute(string cmd); void Execute(std::string cmd);
void LoadGLTextures(); void LoadGLTextures();
void Render(); void Render();
void UnloadMap(); void UnloadMap();
@@ -97,17 +83,14 @@ class Level {
*/ */
Screen screen; Screen screen;
Font glFont; Font glFont;
string nextLevel; std::string nextLevel;
Player* defaultPlayer; Player* defaultPlayer;
uint32_t numTextures; uint32_t numTextures;
string* textureNames; std::string* textureNames;
string bgm; std::string bgm;
#ifdef WIN32
HSTREAM bgmStream;
#endif
unsigned char bgmCDA; unsigned char bgmCDA;
string gamedir; std::string gamedir;
float gravity; float gravity;
bool mlook; bool mlook;
bool showFPS; bool showFPS;
@@ -120,20 +103,20 @@ class Level {
// Map // Map
Triangle* triangles; Triangle* triangles;
uint32_t numTriangles; uint32_t numTriangles;
list<Player> players; std::vector<Player> players;
// list<ENTITY> ents; // std::vector<ENTITY> ents;
list<Texture*> textures; std::vector<Texture*> textures;
Texture menuTextures[NUM_MENU_TEXTURES]; Texture menuTextures[NUM_MENU_TEXTURES];
Window* _window; Window* _window;
// private: // private:
void ConsolePrint(string); void ConsolePrint(std::string);
private: private:
EventManager* _eventManager; EventManager* _eventManager;
string consoleHistory[MAX_CONSOLE_HISTORY_LINES]; std::string consoleHistory[MAX_CONSOLE_HISTORY_LINES];
string consoleOutput[MAX_CONSOLE_OUTPUT_LINES]; std::string consoleOutput[MAX_CONSOLE_OUTPUT_LINES];
string outputText[MAX_OUTPUT_TEXT_LINES]; std::string outputText[MAX_OUTPUT_TEXT_LINES];
}; };
} // End namespace OpenArena } // End namespace OpenArena
#endif // End !defined(OpenArena__level_h__) #endif // End !defined(OpenArena__level_h__)

View File

@@ -17,13 +17,17 @@
* Free Software Foundation, Inc., * * Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/ ***************************************************************************/
#ifdef __linux
#ifdef __linux
// clang-format off
// include necessary header files // include necessary header files
#include "main.h" #include "main.h"
#include "version.h" #include "version.h"
#include "x11.h" #include "x11.h"
using namespace std;
// clang-format on
namespace {} // End namespace
void InitControls(); void InitControls();
@@ -71,11 +75,8 @@ int main(int argc, char** argv) {
// g_Screen.SetOnInit(InitGL); // g_Screen.SetOnInit(InitGL);
// g_Screen.SetOnResize(ResizeGLScene); // g_Screen.SetOnResize(ResizeGLScene);
if (!g_Screen->Open(OPENARENA_VERSION, if (!g_Screen->Open(OPENARENA_VERSION, level->screen.GetWidth(), level->screen.GetHeight(),
level->screen.GetWidth(), level->screen.GetColorDepth(), level->screen.GetFullscreen())) {
level->screen.GetHeight(),
level->screen.GetColorDepth(),
level->screen.GetFullscreen())) {
return 1; return 1;
} }
@@ -174,11 +175,8 @@ int main(int argc, char** argv) {
keys[OpenArena::KEY_F1] = false; keys[OpenArena::KEY_F1] = false;
g_Screen->Close(); g_Screen->Close();
g_Screen->ToggleFullscreen(); g_Screen->ToggleFullscreen();
if (!g_Screen->Open(OPENARENA_VERSION, if (!g_Screen->Open(OPENARENA_VERSION, level->screen.GetWidth(), level->screen.GetHeight(),
level->screen.GetWidth(), level->screen.GetColorDepth(), level->screen.GetFullscreen())) {
level->screen.GetHeight(),
level->screen.GetColorDepth(),
level->screen.GetFullscreen())) {
return 1; return 1;
} }
} }

751
list.h
View File

@@ -1,751 +0,0 @@
/***************************************************************************
* Copyright (C) 2001-2023 by Tom Hicks *
* headhunter3@gmail.com *
* *
* 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 OpenArena__list_h__
#define OpenArena__list_h__
#if defined HAVE_CONFIG_H
#include "config.h"
#endif
#include <cstdlib>
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunknown-pragmas"
#pragma warning(disable : 4715)
namespace OpenArena {
typedef unsigned int LIST_ARRAY_INDEX_TYPE;
/*!
* \brief
* Write brief comment for listNode here.
*
* \param ItemType
* Description of parameter ItemType.
*
* Write detailed description for listNode here.
*
* \remarks
* Write remarks for listNode here.
*
* \see
* Separate items with the '|' character.
*/
template <class ItemType>
class listNode {
public:
/*!
* \brief
* Write brief comment for listNode here.
*
* \throws <exception class>
* Description of criteria for throwing this exception.
*
* Write detailed description for listNode here.
*
* \remarks
* Write remarks for listNode here.
*
* \see
* Separate items with the '|' character.
*/
listNode();
ItemType data;
listNode<ItemType>* next;
};
/*!
* \brief
* Write brief comment for list here.
*
* \param ItemType
* Description of parameter ItemType.
*
* Write detailed description for list here.
*
* \remarks
* Write remarks for list here.
*
* \see
* Separate items with the '|' character.
*/
template <class ItemType>
class list {
public:
/*!
* \brief
* Write brief comment for list here.
*
* \throws <exception class>
* Description of criteria for throwing this exception.
*
* Write detailed description for list here.
*
* \remarks
* Write remarks for list here.
*
* \see
* Separate items with the '|' character.
*/
list();
/*!
* \brief
* Write brief comment for ~list here.
*
* \throws <exception class>
* Description of criteria for throwing this exception.
*
* Write detailed description for ~list here.
*
* \remarks
* Write remarks for ~list here.
*
* \see
* Separate items with the '|' character.
*/
~list();
/*!
* \brief
* Write brief comment for list here.
*
* \param
* Description of parameter .
*
* \throws <exception class>
* Description of criteria for throwing this exception.
*
* Write detailed description for list here.
*
* \remarks
* Write remarks for list here.
*
* \see
* Separate items with the '|' character.
*/
list(const list&);
/*!
* \brief
* Write brief comment for IsEmpty here.
*
* \returns
* Write description of return value here.
*
* \throws <exception class>
* Description of criteria for throwing this exception.
*
* Write detailed description for IsEmpty here.
*
* \remarks
* Write remarks for IsEmpty here.
*
* \see
* Separate items with the '|' character.
*/
bool IsEmpty() const;
/*!
* \brief
* Write brief comment for IsFull here.
*
* \returns
* Write description of return value here.
*
* \throws <exception class>
* Description of criteria for throwing this exception.
*
* Write detailed description for IsFull here.
*
* \remarks
* Write remarks for IsFull here.
*
* \see
* Separate items with the '|' character.
*/
bool IsFull() const;
/*!
* \brief
* Write brief comment for Insert here.
*
* \param newItem
* Description of parameter newItem.
*
* \throws <exception class>
* Description of criteria for throwing this exception.
*
* Write detailed description for Insert here.
*
* \remarks
* Write remarks for Insert here.
*
* \see
* Separate items with the '|' character.
*/
void Insert(ItemType newItem);
/*!
* \brief
* Write brief comment for Remove here.
*
* \param target
* Description of parameter target.
*
* \throws <exception class>
* Description of criteria for throwing this exception.
*
* Write detailed description for Remove here.
*
* \remarks
* Write remarks for Remove here.
*
* \see
* Separate items with the '|' character.
*/
void Remove(ItemType target);
/*!
* \brief
* Write brief comment for Remove here.
*
* \throws <exception class>
* Description of criteria for throwing this exception.
*
* Write detailed description for Remove here.
*
* \remarks
* Write remarks for Remove here.
*
* \see
* Separate items with the '|' character.
*/
void Remove();
/*!
* \brief
* Write brief comment for Retrieve here.
*
* \returns
* Write description of return value here.
*
* \throws <exception class>
* Description of criteria for throwing this exception.
*
* Write detailed description for Retrieve here.
*
* \remarks
* Write remarks for Retrieve here.
*
* \see
* Separate items with the '|' character.
*/
ItemType Retrieve() const;
/*!
* \brief
* Write brief comment for PrevPosition here.
*
* \returns
* Write description of return value here.
*
* \throws <exception class>
* Description of criteria for throwing this exception.
*
* Write detailed description for PrevPosition here.
*
* \remarks
* Write remarks for PrevPosition here.
*
* \see
* Separate items with the '|' character.
*/
bool PrevPosition();
/*!
* \brief
* Write brief comment for NextPosition here.
*
* \returns
* Write description of return value here.
*
* \throws <exception class>
* Description of criteria for throwing this exception.
*
* Write detailed description for NextPosition here.
*
* \remarks
* Write remarks for NextPosition here.
*
* \see
* Separate items with the '|' character.
*/
bool NextPosition();
/*!
* \brief
* Write brief comment for IsFirstPosition here.
*
* \returns
* Write description of return value here.
*
* \throws <exception class>
* Description of criteria for throwing this exception.
*
* Write detailed description for IsFirstPosition here.
*
* \remarks
* Write remarks for IsFirstPosition here.
*
* \see
* Separate items with the '|' character.
*/
bool IsFirstPosition() const;
/*!
* \brief
* Write brief comment for IsLastPosition here.
*
* \returns
* Write description of return value here.
*
* \throws <exception class>
* Description of criteria for throwing this exception.
*
* Write detailed description for IsLastPosition here.
*
* \remarks
* Write remarks for IsLastPosition here.
*
* \see
* Separate items with the '|' character.
*/
bool IsLastPosition() const;
/*!
* \brief
* Write brief comment for FirstPosition here.
*
* \throws <exception class>
* Description of criteria for throwing this exception.
*
* Write detailed description for FirstPosition here.
*
* \remarks
* Write remarks for FirstPosition here.
*
* \see
* Separate items with the '|' character.
*/
void FirstPosition();
/*!
* \brief
* Write brief comment for LastPosition here.
*
* \throws <exception class>
* Description of criteria for throwing this exception.
*
* Write detailed description for LastPosition here.
*
* \remarks
* Write remarks for LastPosition here.
*
* \see
* Separate items with the '|' character.
*/
void LastPosition();
/*!
* \brief
* Write brief comment for Clear here.
*
* \throws <exception class>
* Description of criteria for throwing this exception.
*
* Write detailed description for Clear here.
*
* \remarks
* Write remarks for Clear here.
*
* \see
* Separate items with the '|' character.
*/
void Clear();
/*!
* \brief
* Write brief comment for Contains here.
*
* \param
* Description of parameter .
*
* \returns
* Write description of return value here.
*
* \throws <exception class>
* Description of criteria for throwing this exception.
*
* Write detailed description for Contains here.
*
* \remarks
* Write remarks for Contains here.
*
* \see
* Separate items with the '|' character.
*/
bool Contains(ItemType) const;
/*!
* \brief
* Write brief comment for Length here.
*
* \returns
* Write description of return value here.
*
* \throws <exception class>
* Description of criteria for throwing this exception.
*
* Write detailed description for Length here.
*
* \remarks
* Write remarks for Length here.
*
* \see
* Separate items with the '|' character.
*/
unsigned int Length();
/*!
* \brief
* Write brief comment for operator = here.
*
* \param
* Description of parameter .
*
* \throws <exception class>
* Description of criteria for throwing this exception.
*
* Write detailed description for operator = here.
*
* \remarks
* Write remarks for operator = here.
*
* \see
* Separate items with the '|' character.
*/
void operator=(const list<ItemType>&);
/*!
* \brief
* Write brief comment for operator [] here.
*
* \param
* Description of parameter .
*
* \returns
* Write description of return value here.
*
* \throws <exception class>
* Description of criteria for throwing this exception.
*
* Write detailed description for operator [] here.
*
* \remarks
* Write remarks for operator [] here.
*
* \see
* Separate items with the '|' character.
*/
ItemType operator[](LIST_ARRAY_INDEX_TYPE) const;
/*!
* \brief
* Write brief comment for operator [] here.
*
* \param
* Description of parameter .
*
* \returns
* Write description of return value here.
*
* \throws <exception class>
* Description of criteria for throwing this exception.
*
* Write detailed description for operator [] here.
*
* \remarks
* Write remarks for operator [] here.
*
* \see
* Separate items with the '|' character.
*/
ItemType& operator[](LIST_ARRAY_INDEX_TYPE);
private:
listNode<ItemType>* head;
listNode<ItemType>* tail;
listNode<ItemType>* currPos;
};
template <class ItemType>
listNode<ItemType>::listNode() {
next = NULL;
}
template <class ItemType>
list<ItemType>::list() {
head = NULL;
tail = NULL;
currPos = NULL;
}
template <class ItemType>
list<ItemType>::~list() {
currPos = NULL;
while (head != NULL) {
tail = head;
head = head->next;
delete tail;
tail = NULL;
}
}
template <class ItemType>
list<ItemType>::list(const list<ItemType>& rtOp) {
head = NULL;
tail = NULL;
currPos = NULL;
operator=(rtOp);
}
template <class ItemType>
void list<ItemType>::Clear() {
while (head) Remove(head->data);
}
template <class ItemType>
void list<ItemType>::operator=(const list<ItemType>& rtOp) {
Clear();
if (!rtOp.IsEmpty()) {
listNode<ItemType>* temp = rtOp.head->next;
listNode<ItemType>* temp2 = NULL;
if (temp != NULL) {
head = new listNode<ItemType>;
head->data = rtOp.head->data;
tail = head;
temp2 = head;
}
while (temp != NULL) {
temp2->next = new listNode<ItemType>;
temp2 = temp2->next;
temp2->data = temp->data;
temp = temp->next;
}
tail = temp2;
}
}
template <class ItemType>
bool list<ItemType>::IsEmpty() const {
return head == NULL;
}
template <class ItemType>
bool list<ItemType>::IsFull() const {
return false;
}
template <class ItemType>
void list<ItemType>::Insert(ItemType newItem) {
listNode<ItemType>* temp = head;
listNode<ItemType>* temp2 = NULL;
if (head == NULL) {
temp = tail = head = new listNode<ItemType>;
} else {
if (newItem < head->data) {
temp2 = head;
temp = head = new listNode<ItemType>;
head->next = temp2;
temp2 = NULL;
} else {
// temp = head;
while (temp->next != NULL && newItem > temp->next->data) {
temp = temp->next;
}
temp2 = temp->next;
temp = temp->next = new listNode<ItemType>;
temp->next = temp2;
temp2 = NULL;
}
}
temp->data = newItem;
if (temp->next == NULL) {
tail = temp;
}
}
template <class ItemType>
void list<ItemType>::Remove(ItemType target) {
if (head != NULL) {
listNode<ItemType>* temp = head;
listNode<ItemType>* temp2 = head;
while (temp->next != NULL && temp->data != target) {
temp2 = temp;
temp = temp->next;
}
if (temp->data == target) {
if (temp != head) {
temp2->next = temp->next;
delete temp;
} else {
if (tail == head) tail = NULL;
head = head->next;
delete temp2;
}
}
}
}
template <class ItemType>
bool list<ItemType>::PrevPosition() {
if (currPos != head) {
tail->next = currPos;
currPos = head;
if (currPos != tail->next) {
while (currPos->next != tail->next) {
currPos = currPos->next;
}
}
tail->next = NULL;
return true;
} else {
return false;
}
}
template <class ItemType>
bool list<ItemType>::NextPosition() {
if (currPos != tail) {
currPos = currPos->next;
return true;
} else {
return false;
}
}
template <class ItemType>
void list<ItemType>::Remove() {
if (currPos != NULL) {
tail->next = currPos;
currPos = currPos->next;
delete tail->next;
tail->next = NULL;
}
}
template <class ItemType>
ItemType list<ItemType>::Retrieve() const {
if (currPos != NULL) return currPos->data;
}
template <class ItemType>
bool list<ItemType>::IsFirstPosition() const {
return currPos == head;
}
template <class ItemType>
bool list<ItemType>::IsLastPosition() const {
return currPos == tail;
}
template <class ItemType>
void list<ItemType>::FirstPosition() {
currPos = head;
}
template <class ItemType>
void list<ItemType>::LastPosition() {
currPos = tail;
}
template <class ItemType>
ItemType list<ItemType>::operator[](LIST_ARRAY_INDEX_TYPE index) const {
if (head == NULL) {
// We should throw an exception here but instead I'll just return shit guess
// for now if somebody does this they're just fucked.
} else {
listNode<ItemType>* temp = head;
LIST_ARRAY_INDEX_TYPE current;
for (current = 0; current < index; current++) {
if (temp->next == NULL) {
temp->next = new listNode<ItemType>;
}
temp = temp->next;
}
return temp->data;
}
}
template <class ItemType>
ItemType& list<ItemType>::operator[](LIST_ARRAY_INDEX_TYPE index) {
if (head == NULL) {
tail = currPos = head = new listNode<ItemType>;
return (ItemType&)(head->data);
} else {
listNode<ItemType>* temp = head;
LIST_ARRAY_INDEX_TYPE current;
for (current = 0; current < index; current++) {
if (temp->next == NULL) {
temp->next = new listNode<ItemType>;
}
temp = temp->next;
}
return (ItemType&)(temp->data);
}
}
template <class ItemType>
unsigned int list<ItemType>::Length() {
if (head == NULL) {
return 0;
} else {
int len = 1;
listNode<ItemType>* temp = head->next;
while (temp != NULL) {
temp = temp->next;
len++;
}
return len;
}
}
template <class ItemType>
bool list<ItemType>::Contains(ItemType value) const {
listNode<ItemType>* temp = head;
while (temp != NULL) {
if (temp->data == value) {
return true;
}
temp = temp->next;
}
return false;
}
}; // namespace OpenArena
#pragma clang diagnostic pop
#endif // End !defined(OpenArena__list_h__)

View File

@@ -17,7 +17,9 @@
* Free Software Foundation, Inc., * * Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/ ***************************************************************************/
#ifdef __APPLE__ #ifdef __APPLE__
// clang-format off
#include "DrawEvent.h" #include "DrawEvent.h"
#include "EventManager.h" #include "EventManager.h"
#include "KeyPressEvent.h" #include "KeyPressEvent.h"
@@ -25,8 +27,11 @@
#include "main.h" #include "main.h"
#include "version.h" #include "version.h"
#include "x11.h" #include "x11.h"
// clang-format on
// include necessary header files // include necessary header files
using namespace std; namespace {} // End namespace
bool g_done = false; bool g_done = false;
@@ -105,11 +110,8 @@ int main(int argc, char** argv) {
level->screen.SetColorDepth(24); level->screen.SetColorDepth(24);
} }
if (!g_Screen->Open(OPENARENA_VERSION, if (!g_Screen->Open(OPENARENA_VERSION, level->screen.GetWidth(), level->screen.GetHeight(),
level->screen.GetWidth(), level->screen.GetColorDepth(), level->screen.GetFullscreen())) {
level->screen.GetHeight(),
level->screen.GetColorDepth(),
level->screen.GetFullscreen())) {
return 1; return 1;
} }
@@ -201,11 +203,8 @@ int main(int argc, char** argv) {
keys[OpenArena::KEY_F1] = false; keys[OpenArena::KEY_F1] = false;
g_Screen->Close(); g_Screen->Close();
g_Screen->ToggleFullscreen(); g_Screen->ToggleFullscreen();
if (!g_Screen->Open(OPENARENA_VERSION, if (!g_Screen->Open(OPENARENA_VERSION, level->screen.GetWidth(), level->screen.GetHeight(),
level->screen.GetWidth(), level->screen.GetColorDepth(), level->screen.GetFullscreen())) {
level->screen.GetHeight(),
level->screen.GetColorDepth(),
level->screen.GetFullscreen())) {
return 1; return 1;
} }
} }
@@ -245,11 +244,8 @@ int main(int argc, char** argv) {
level->screen.SetColorDepth(24); level->screen.SetColorDepth(24);
} }
if (!g_Screen->Open(OPENARENA_VERSION, if (!g_Screen->Open(OPENARENA_VERSION, level->screen.GetWidth(), level->screen.GetHeight(),
level->screen.GetWidth(), level->screen.GetColorDepth(), level->screen.GetFullscreen())) {
level->screen.GetHeight(),
level->screen.GetColorDepth(),
level->screen.GetFullscreen())) {
return 1; return 1;
} }

View File

@@ -17,10 +17,13 @@
* Free Software Foundation, Inc., * * Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/ ***************************************************************************/
#if defined __APPLE__ #if defined __APPLE__
// clang-format off
#include <AGL/agl.h> #include <AGL/agl.h>
#include <Carbon/Carbon.h> #include <Carbon/Carbon.h>
#include <OpenGL/gl.h> #include "opengl.h"
// clang-format on
/* /*
OSStatus main(int argc, char** argv) OSStatus main(int argc, char** argv)

72
main.h
View File

@@ -17,12 +17,11 @@
* Free Software Foundation, Inc., * * Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/ ***************************************************************************/
#ifndef OpenArena__main_h__ #ifndef OpenArena__main_h__
#define OpenArena__main_h__ #define OpenArena__main_h__
// clang-format off
#if defined HAVE_CONFIG_H
#include "config.h" #include "config.h"
#endif
#if defined USE_GLX #if defined USE_GLX
#include <GL/gl.h> // Header file for OpenGL32 library #include <GL/gl.h> // Header file for OpenGL32 library
@@ -32,9 +31,9 @@
#elif defined USE_CGL #elif defined USE_CGL
#error unimplemented method #error unimplemented method
#elif defined USE_WGL #elif defined USE_WGL
#include <windows.h>
#include <GL/gl.h> // Header file for OpenGL32 library #include <GL/gl.h> // Header file for OpenGL32 library
#include <GL/glu.h> // Header file for Glu32 library #include <GL/glu.h> // Header file for Glu32 library
#include <windows.h>
#endif #endif
#include <math.h> #include <math.h>
@@ -49,10 +48,7 @@
#include "vector.h" #include "vector.h"
#include "window.h" #include "window.h"
#include "worlddefs.h" #include "worlddefs.h"
#pragma clang diagnostic push // clang-format on
#pragma clang diagnostic ignored "-Wunknown-pragmas"
#pragma warning(disable : 4786)
#pragma clang diagnostic pop
////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Variables // Variables
@@ -66,7 +62,7 @@ extern OpenArena::Vec2i g_mousePosition;
#ifdef WIN32 #ifdef WIN32
extern POINT mpos; extern POINT mpos;
#endif #endif // OpenArena__main_h__
extern float lastTime; // This will hold the time from the last frame extern float lastTime; // This will hold the time from the last frame
extern float currentTime; extern float currentTime;
@@ -76,62 +72,8 @@ extern float currentTime;
// This shouldn't need to be here // This shouldn't need to be here
// LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); // Declaration for WndProc // LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); // Declaration for WndProc
/*! void InitControls(); // Sets up player controls
* \brief int InitGL(); // All setup for OpenGL goes here
* Write brief comment for InitControls here.
*
* \throws <exception class>
* Description of criteria for throwing this exception.
*
* Write detailed description for InitControls here.
*
* \remarks
* Write remarks for InitControls here.
*
* \see
* Separate items with the '|' character.
*/
void InitControls(); // Sets up player controls
/*!
* \brief
* Write brief comment for InitGL here.
*
* \returns
* Write description of return value here.
*
* \throws <exception class>
* Description of criteria for throwing this exception.
*
* Write detailed description for InitGL here.
*
* \remarks
* Write remarks for InitGL here.
*
* \see
* Separate items with the '|' character.
*/
int InitGL(); // All setup for OpenGL goes here
/*!
* \brief
* Write brief comment for ReSizeGLScene here.
*
* \param width
* Description of parameter width.
*
* \param height
* Description of parameter height.
*
* \throws <exception class>
* Description of criteria for throwing this exception.
*
* Write detailed description for ReSizeGLScene here.
*
* \remarks
* Write remarks for ReSizeGLScene here.
*
* \see
* Separate items with the '|' character.
*/
void ReSizeGLScene(GLsizei width, GLsizei height); // Resize and initialize the GL window void ReSizeGLScene(GLsizei width, GLsizei height); // Resize and initialize the GL window
int DrawGLScene(OpenArena::Level* level); int DrawGLScene(OpenArena::Level* level);

View File

@@ -17,16 +17,16 @@
* Free Software Foundation, Inc., * * Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/ ***************************************************************************/
#ifndef OpenArena__mydefs_h__ #ifndef OpenArena__mydefs_h__
#define OpenArena__mydefs_h__ #define OpenArena__mydefs_h__
// clang-format off
#if defined HAVE_CONFIG_H
#include "config.h" #include "config.h"
#endif
#ifdef WIN32 // This whole file is windows specific right now #ifdef WIN32 // This whole file is windows specific right now
#include <windows.h> #include <windows.h>
static HWND g_hWnd = NULL; static HWND g_hWnd = NULL;
#endif #endif
// clang-format on
#endif // End !defined(OpenArena__mydefs_h__) #endif // End !defined(OpenArena__mydefs_h__)

View File

@@ -17,31 +17,41 @@
* Free Software Foundation, Inc., * * Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/ ***************************************************************************/
#include "mygl.h"
// clang-format off
#include "mygl.h"
#include "Logger.h"
#include "bmp.h" #include "bmp.h"
#include "strmanip.h" #include "strmanip.h"
#include "texture.h" #include "texture.h"
#include "tga.h" #include "tga.h"
// clang-format on
namespace OpenArena { namespace OpenArena {
#pragma clang diagnostic push namespace {
#pragma clang diagnostic ignored "-Wdeprecated-declarations" using std::shared_ptr;
using std::string;
} // End namespace
void FreeGLTexture(GLuint& texture) { void FreeGLTexture(GLuint& texture) {
glDeleteTextures(1, &texture); glDeleteTextures(1, &texture);
} }
bool LoadGLTexture(string fn, GLuint& texture, GLuint mag, GLuint min) { bool LoadGLTexture(string fn, GLuint& texture, GLuint mag, GLuint min) {
string method_name = "OpenArena::LoadGLTexture(string, GLuint&, GLuint, GLuint) ";
if (Right(tolower(fn), 4) == ".bmp") { if (Right(tolower(fn), 4) == ".bmp") {
TextureImage* texImage = NULL; Logger::LogDebug(method_name + "Loading a bitmap.");
if ((texImage = LoadBMP(fn.c_str()))) { shared_ptr<BitmapImage> bmp = BitmapImage::FromFile(fn);
Logger::LogDebug((string) "bitmap is " + (bmp ? "not null" : "null"));
TextureImage* texImage = bmp->ToTextureImage();
if (texImage) {
glGenTextures(1, &texture); glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture); glBindTexture(GL_TEXTURE_2D, texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexImage2D( glTexImage2D(GL_TEXTURE_2D, 0, 3, texImage->sizeX, texImage->sizeY, 0, texImage->type, GL_UNSIGNED_BYTE,
GL_TEXTURE_2D, 0, 3, texImage->sizeX, texImage->sizeY, 0, texImage->type, GL_UNSIGNED_BYTE, texImage->data); texImage->data);
if (texImage) // Just in case somehow the file was empty or unloadable if (texImage) // Just in case somehow the file was empty or unloadable
{ {
@@ -53,12 +63,16 @@ bool LoadGLTexture(string fn, GLuint& texture, GLuint mag, GLuint min) {
return false; return false;
} }
} else if (Right(tolower(fn), 4) == ".tga") { } else if (Right(tolower(fn), 4) == ".tga") {
TextureImage* texImage = NULL; Logger::LogDebug(method_name + "Loading a tga file.");
if ((texImage = LoadTGA(fn.c_str()))) { shared_ptr<TargaImage> tga = TargaImage::FromFile(fn);
Logger::LogDebug(method_name + "tga is " + (tga ? "not null" : "null"));
TextureImage* texImage = tga->FromFile(fn)->ToTextureImage();
Logger::LogDebug(method_name + "texImage is " + (texImage ? "not null" : "null"));
if ((texImage)) {
glGenTextures(1, &texture); glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture); glBindTexture(GL_TEXTURE_2D, texture);
glTexImage2D( glTexImage2D(GL_TEXTURE_2D, 0, 3, texImage->sizeX, texImage->sizeY, 0, texImage->type, GL_UNSIGNED_BYTE,
GL_TEXTURE_2D, 0, 3, texImage->sizeX, texImage->sizeY, 0, texImage->type, GL_UNSIGNED_BYTE, texImage->data); texImage->data);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
@@ -67,16 +81,18 @@ bool LoadGLTexture(string fn, GLuint& texture, GLuint mag, GLuint min) {
if (texImage->data) free(texImage->data); if (texImage->data) free(texImage->data);
free(texImage); free(texImage);
} }
Logger::LogDebug(method_name + "returning true");
return true; return true;
} else { } else {
Logger::LogDebug(method_name + "returning false from 1");
return false; return false;
} }
} else { } else {
Logger::LogDebug(method_name + "returning false from 2");
return false; return false;
} }
} }
#pragma clang diagnostic pop
} // End namespace OpenArena
OpenArena::Window* g_Screen = new OpenArena::Window(); OpenArena::Window* g_Screen = new OpenArena::Window();
} // End namespace OpenArena

84
mygl.h
View File

@@ -17,93 +17,25 @@
* Free Software Foundation, Inc., * * Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/ ***************************************************************************/
#ifndef OpenArena__mygl_h__ #ifndef OpenArena__mygl_h__
#define OpenArena__mygl_h__ #define OpenArena__mygl_h__
// clang-format off
#if defined HAVE_CONFIG_H
#include "config.h" #include "config.h"
#endif #include "opengl.h"
#if defined USE_GLX
#include <GL/gl.h>
#include <GL/glu.h>
#elif defined USE_AGL
#include <OpenGL/OpenGL.h>
#include <OpenGL/gl.h>
#include <OpenGL/glu.h>
// #error unimplemented method
#elif defined USE_CGL
#error unimplemented method
#elif defined USE_WGL
#include <GL/gl.h>
#include <GL/glu.h>
#include <windows.h>
#endif
#include <OpenGL/gl.h>
#include "window.h" #include "window.h"
// clang-format on
using namespace std;
#ifdef WIN32 #ifdef WIN32
// These this is windows specific // These this is windows specific
static HINSTANCE hInstance; // Application instance static HINSTANCE hInstance; // Application instance
#endif #endif
namespace OpenArena {
// TODO: Move this to behidden in mygl.cpp. // TODO: Move this to behidden in mygl.cpp.
extern OpenArena::Window* g_Screen; extern OpenArena::Window* g_Screen;
namespace OpenArena { bool LoadGLTexture(std::string, GLuint&, GLuint = GL_LINEAR, GLuint = GL_LINEAR);
/*!
* \brief
* Write brief comment for LoadGLTexture here.
*
* \param
* Description of parameter .
*
* \param
* Description of parameter .
*
* \param
* Description of parameter .
*
* \param
* Description of parameter .
*
* \returns
* Write description of return value here.
*
* \throws <exception class>
* Description of criteria for throwing this exception.
*
* Write detailed description for LoadGLTexture here.
*
* \remarks
* Write remarks for LoadGLTexture here.
*
* \see
* Separate items with the '|' character.
*/
bool LoadGLTexture(string, GLuint&, GLuint = GL_LINEAR, GLuint = GL_LINEAR);
/*!
* \brief
* Write brief comment for FreeGLTexture here.
*
* \param
* Description of parameter .
*
* \throws <exception class>
* Description of criteria for throwing this exception.
*
* Write detailed description for FreeGLTexture here.
*
* \remarks
* Write remarks for FreeGLTexture here.
*
* \see
* Separate items with the '|' character.
*/
void FreeGLTexture(GLuint&); void FreeGLTexture(GLuint&);
}; // namespace OpenArena }; // namespace OpenArena
#endif #endif // !defined(OpenArena__mygl_h__)

View File

@@ -17,11 +17,13 @@
* Free Software Foundation, Inc., * * Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/ ***************************************************************************/
// clang-format off
#include "myglFont.h" #include "myglFont.h"
// clang-format on
namespace OpenArena { namespace OpenArena {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
Font::Font() { Font::Font() {
status = 0; status = 0;
@@ -123,5 +125,4 @@ short Font::ScreenHeight() {
return screenHeight; return screenHeight;
} }
#pragma clang diagnostic pop
} // End namespace OpenArena } // End namespace OpenArena

View File

@@ -17,28 +17,17 @@
* Free Software Foundation, Inc., * * Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/ ***************************************************************************/
#ifndef OpenArena__myglFont_h__ #ifndef OpenArena__myglFont_h__
#define OpenArena__myglFont_h__ #define OpenArena__myglFont_h__
#if defined HAVE_CONFIG_H // clang-format off
#include "config.h" #include "config.h"
#endif
#include "mygl.h" #include "mygl.h"
// clang-format on
namespace OpenArena { namespace OpenArena {
/*!
* \brief
* Write brief comment for Font here.
*
* Write detailed description for Font here.
*
* \remarks
* Write remarks for Font here.
*
* \see
* Separate items with the '|' character.
*/
class Font { class Font {
private: private:
short screenWidth; short screenWidth;
@@ -48,223 +37,16 @@ class Font {
bool status; bool status;
public: public:
/*!
* \brief
* Write brief comment for Font here.
*
* \throws <exception class>
* Description of criteria for throwing this exception.
*
* Write detailed description for Font here.
*
* \remarks
* Write remarks for Font here.
*
* \see
* Separate items with the '|' character.
*/
Font(); Font();
/*!
* \brief
* Write brief comment for ~Font here.
*
* \throws <exception class>
* Description of criteria for throwing this exception.
*
* Write detailed description for ~Font here.
*
* \remarks
* Write remarks for ~Font here.
*
* \see
* Separate items with the '|' character.
*/
~Font(); ~Font();
/*!
* \brief
* Write brief comment for BuildFont here.
*
* \param
* Description of parameter .
*
* \returns
* Write description of return value here.
*
* \throws <exception class>
* Description of criteria for throwing this exception.
*
* Write detailed description for BuildFont here.
*
* \remarks
* Write remarks for BuildFont here.
*
* \see
* Separate items with the '|' character.
*/
bool BuildFont(const char*); bool BuildFont(const char*);
/*!
* \brief
* Write brief comment for FreeFont here.
*
* \returns
* Write description of return value here.
*
* \throws <exception class>
* Description of criteria for throwing this exception.
*
* Write detailed description for FreeFont here.
*
* \remarks
* Write remarks for FreeFont here.
*
* \see
* Separate items with the '|' character.
*/
bool FreeFont(); bool FreeFont();
/*!
* \brief
* Write brief comment for Print here.
*
* \param
* Description of parameter .
*
* \param
* Description of parameter .
*
* \param
* Description of parameter .
*
* \param
* Description of parameter .
*
* \throws <exception class>
* Description of criteria for throwing this exception.
*
* Write detailed description for Print here.
*
* \remarks
* Write remarks for Print here.
*
* \see
* Separate items with the '|' character.
*/
void Print(int, int, const char*, unsigned int = 0); void Print(int, int, const char*, unsigned int = 0);
/*!
* \brief
* Write brief comment for Loaded here.
*
* \returns
* Write description of return value here.
*
* \throws <exception class>
* Description of criteria for throwing this exception.
*
* Write detailed description for Loaded here.
*
* \remarks
* Write remarks for Loaded here.
*
* \see
* Separate items with the '|' character.
*/
bool Loaded(); bool Loaded();
/*!
* \brief
* Write brief comment for SetScreenDimensions here.
*
* \param
* Description of parameter .
*
* \param
* Description of parameter .
*
* \throws <exception class>
* Description of criteria for throwing this exception.
*
* Write detailed description for SetScreenDimensions here.
*
* \remarks
* Write remarks for SetScreenDimensions here.
*
* \see
* Separate items with the '|' character.
*/
void SetScreenDimensions(short, short); void SetScreenDimensions(short, short);
/*!
* \brief
* Write brief comment for SetScreenWidth here.
*
* \param
* Description of parameter .
*
* \throws <exception class>
* Description of criteria for throwing this exception.
*
* Write detailed description for SetScreenWidth here.
*
* \remarks
* Write remarks for SetScreenWidth here.
*
* \see
* Separate items with the '|' character.
*/
void SetScreenWidth(short); void SetScreenWidth(short);
/*!
* \brief
* Write brief comment for SetScreenHeight here.
*
* \param
* Description of parameter .
*
* \throws <exception class>
* Description of criteria for throwing this exception.
*
* Write detailed description for SetScreenHeight here.
*
* \remarks
* Write remarks for SetScreenHeight here.
*
* \see
* Separate items with the '|' character.
*/
void SetScreenHeight(short); void SetScreenHeight(short);
/*!
* \brief
* Write brief comment for ScreenWidth here.
*
* \returns
* Write description of return value here.
*
* \throws <exception class>
* Description of criteria for throwing this exception.
*
* Write detailed description for ScreenWidth here.
*
* \remarks
* Write remarks for ScreenWidth here.
*
* \see
* Separate items with the '|' character.
*/
short ScreenWidth(); short ScreenWidth();
/*!
* \brief
* Write brief comment for ScreenHeight here.
*
* \returns
* Write description of return value here.
*
* \throws <exception class>
* Description of criteria for throwing this exception.
*
* Write detailed description for ScreenHeight here.
*
* \remarks
* Write remarks for ScreenHeight here.
*
* \see
* Separate items with the '|' character.
*/
short ScreenHeight(); short ScreenHeight();
}; };
} // End namespace OpenArena } // End namespace OpenArena

View File

@@ -17,11 +17,22 @@
* Free Software Foundation, Inc., * * Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/ ***************************************************************************/
// clang-format off
#include "myglTexture.h" #include "myglTexture.h"
using namespace OpenArena; #include <string>
#include "Logger.h"
// clang-format on
namespace OpenArena { namespace OpenArena {
namespace {
using std::string;
using std::to_string;
} // End namespace
Texture::Texture() { Texture::Texture() {
Logger::LogDebug("OpenArena::Texture::Texture() Making a new unloaded texture.");
id = 0xFFFFFFFF; id = 0xFFFFFFFF;
filename = ""; filename = "";
minFilter = GL_LINEAR; minFilter = GL_LINEAR;
@@ -32,39 +43,55 @@ Texture::~Texture() {
Free(); Free();
} }
string Texture::Filename() { string Texture::Filename() const {
return filename; return filename;
} }
GLuint Texture::ID() { GLuint Texture::ID() const {
return id; return id;
} }
bool Texture::Loaded() { bool Texture::Loaded() const {
return filename != ""; return filename != "";
} }
bool Texture::Load(string fn) { bool Texture::Load(string fn) {
if (Loaded()) Free(); const string method_name = "OpenArena::Texture::Load ";
Logger::LogDebug(method_name + "Loading texture from " + fn);
if (Loaded()) {
Logger::LogDebug(method_name + "Freeing old texture " + filename);
Free();
}
if (LoadGLTexture(fn.c_str(), id, minFilter, magFilter)) { if (LoadGLTexture(fn.c_str(), id, minFilter, magFilter)) {
Logger::LogDebug(method_name + "Texture load successful");
filename = fn; filename = fn;
return true; return true;
} else { } else {
Logger::LogError(method_name + "error while loading texture from " + fn
+ ", with min_filter = " + to_string(minFilter) + ", and mag_filter = " + to_string(magFilter));
id = 0xFFFFFFFF; id = 0xFFFFFFFF;
return false; return false;
} }
} }
bool Texture::Load(string fn, GLuint min, GLuint mag) { bool Texture::Load(string fn, GLuint min, GLuint mag) {
if (Loaded()) Free(); string method_name = "OpenArena::Texture::Load(string, GLuint, GLuint) ";
Logger::LogDebug(method_name + "Loading texture from " + fn);
if (Loaded()) {
Logger::LogDebug(method_name + "Freeing old texture " + fn);
Free();
}
if (LoadGLTexture(fn.c_str(), id, min, mag)) { if (LoadGLTexture(fn.c_str(), id, min, mag)) {
Logger::LogDebug(method_name + "Texture load successful");
filename = fn; filename = fn;
minFilter = min; minFilter = min;
magFilter = mag; magFilter = mag;
return true; return true;
} else { } else {
Logger::LogError(method_name + "error while loading texture from " + fn + ", with min_filter = " + to_string(min)
+ ", and mag_filter = " + to_string(mag));
id = 0xFFFFFFFF; id = 0xFFFFFFFF;
return false; return false;
} }
@@ -72,9 +99,7 @@ bool Texture::Load(string fn, GLuint min, GLuint mag) {
void Texture::Free() { void Texture::Free() {
if (Loaded()) { if (Loaded()) {
// This is only temporarily removed for mac os x FreeGLTexture(id);
// TODO make this work on all operating systems
// FreeGLTexture(id);
minFilter = GL_LINEAR; minFilter = GL_LINEAR;
magFilter = GL_LINEAR; magFilter = GL_LINEAR;
filename = ""; filename = "";
@@ -82,27 +107,30 @@ void Texture::Free() {
} }
} }
bool Texture::operator<(const Texture& rtOp) { bool Texture::operator<(const Texture& rtOp) const {
return id < rtOp.id; return id < rtOp.id;
} }
bool Texture::operator<=(const Texture& rtOp) { bool Texture::operator<=(const Texture& rtOp) const {
return id <= rtOp.id; return id <= rtOp.id;
} }
bool Texture::operator==(const Texture& rtOp) { bool Texture::operator==(const Texture& rtOp) const {
return id == rtOp.id; return id == rtOp.id;
} }
bool Texture::operator!=(const Texture& rtOp) { bool Texture::operator!=(const Texture& rtOp) const {
return id != rtOp.id; return id != rtOp.id;
} }
bool Texture::operator>=(const Texture& rtOp) { bool Texture::operator>=(const Texture& rtOp) const {
return id >= rtOp.id; return id >= rtOp.id;
} }
bool Texture::operator>(const Texture& rtOp) { bool Texture::operator>(const Texture& rtOp) const {
return id > rtOp.id; return id > rtOp.id;
} }
Texture kUnknownTexture = Texture();
} // End namespace OpenArena } // End namespace OpenArena

View File

@@ -17,321 +17,33 @@
* Free Software Foundation, Inc., * * Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/ ***************************************************************************/
#ifndef OpenArena__myglTexture_h__ #ifndef OpenArena__myglTexture_h__
#define OpenArena__myglTexture_h__ #define OpenArena__myglTexture_h__
// clang-format off
#if defined HAVE_CONFIG_H
#include "config.h" #include "config.h"
#endif
#include <string> #include <string>
#include "mygl.h" #include "mygl.h"
using namespace std; // clang-format on
namespace OpenArena { namespace OpenArena {
/*!
* \brief
* Write brief comment for Texture here.
*
* Write detailed description for Texture here.
*
* \remarks
* Write remarks for Texture here.
*
* \see
* Separate items with the '|' character.
*/
class Texture { class Texture {
public: public:
/*!
* \brief
* Write brief comment for Texture here.
*
* \throws <exception class>
* Description of criteria for throwing this exception.
*
* Write detailed description for Texture here.
*
* \remarks
* Write remarks for Texture here.
*
* \see
* Separate items with the '|' character.
*/
Texture(); Texture();
/*!
* \brief
* Write brief comment for ~Texture here.
*
* \throws <exception class>
* Description of criteria for throwing this exception.
*
* Write detailed description for ~Texture here.
*
* \remarks
* Write remarks for ~Texture here.
*
* \see
* Separate items with the '|' character.
*/
~Texture(); ~Texture();
/*! std::string Filename() const;
* \brief uint32_t ID() const;
* Write brief comment for Filename here. bool Load(std::string filename);
* bool Load(std::string filename, uint32_t min, uint32_t mag);
* \returns
* Write description of return value here.
*
* \throws <exception class>
* Description of criteria for throwing this exception.
*
* Write detailed description for Filename here.
*
* \remarks
* Write remarks for Filename here.
*
* \see
* Separate items with the '|' character.
*/
string Filename();
/*!
* \brief
* Write brief comment for ID here.
*
* \returns
* Write description of return value here.
*
* \throws <exception class>
* Description of criteria for throwing this exception.
*
* Write detailed description for ID here.
*
* \remarks
* Write remarks for ID here.
*
* \see
* Separate items with the '|' character.
*/
uint32_t ID();
/*!
* \brief
* Write brief comment for Load here.
*
* \param filename
* Description of parameter filename.
*
* \returns
* Write description of return value here.
*
* \throws <exception class>
* Description of criteria for throwing this exception.
*
* Write detailed description for Load here.
*
* \remarks
* Write remarks for Load here.
*
* \see
* Separate items with the '|' character.
*/
bool Load(string filename);
/*!
* \brief
* Write brief comment for Load here.
*
* \param filename
* Description of parameter filename.
*
* \param min
* Description of parameter min.
*
* \param mag
* Description of parameter mag.
*
* \returns
* Write description of return value here.
*
* \throws <exception class>
* Description of criteria for throwing this exception.
*
* Write detailed description for Load here.
*
* \remarks
* Write remarks for Load here.
*
* \see
* Separate items with the '|' character.
*/
bool Load(string filename, uint32_t min, uint32_t mag);
/*!
* \brief
* Write brief comment for Free here.
*
* \throws <exception class>
* Description of criteria for throwing this exception.
*
* Write detailed description for Free here.
*
* \remarks
* Write remarks for Free here.
*
* \see
* Separate items with the '|' character.
*/
void Free(); void Free();
/*! bool Loaded() const;
* \brief bool operator<(const Texture&) const;
* Write brief comment for Loaded here. bool operator<=(const Texture&) const;
* bool operator==(const Texture&) const;
* \returns bool operator!=(const Texture&) const;
* Write description of return value here. bool operator>=(const Texture&) const;
* bool operator>(const Texture&) const;
* \throws <exception class>
* Description of criteria for throwing this exception.
*
* Write detailed description for Loaded here.
*
* \remarks
* Write remarks for Loaded here.
*
* \see
* Separate items with the '|' character.
*/
bool Loaded();
/*!
* \brief
* Write brief comment for operator < here.
*
* \param
* Description of parameter .
*
* \returns
* Write description of return value here.
*
* \throws <exception class>
* Description of criteria for throwing this exception.
*
* Write detailed description for operator < here.
*
* \remarks
* Write remarks for operator < here.
*
* \see
* Separate items with the '|' character.
*/
bool operator<(const Texture&);
/*!
* \brief
* Write brief comment for operator <= here.
*
* \param
* Description of parameter .
*
* \returns
* Write description of return value here.
*
* \throws <exception class>
* Description of criteria for throwing this exception.
*
* Write detailed description for operator <= here.
*
* \remarks
* Write remarks for operator <= here.
*
* \see
* Separate items with the '|' character.
*/
bool operator<=(const Texture&);
/*!
* \brief
* Write brief comment for operator == here.
*
* \param
* Description of parameter .
*
* \returns
* Write description of return value here.
*
* \throws <exception class>
* Description of criteria for throwing this exception.
*
* Write detailed description for operator == here.
*
* \remarks
* Write remarks for operator == here.
*
* \see
* Separate items with the '|' character.
*/
bool operator==(const Texture&);
/*!
* \brief
* Write brief comment for operator != here.
*
* \param
* Description of parameter .
*
* \returns
* Write description of return value here.
*
* \throws <exception class>
* Description of criteria for throwing this exception.
*
* Write detailed description for operator != here.
*
* \remarks
* Write remarks for operator != here.
*
* \see
* Separate items with the '|' character.
*/
bool operator!=(const Texture&);
/*!
* \brief
* Write brief comment for operator >= here.
*
* \param
* Description of parameter .
*
* \returns
* Write description of return value here.
*
* \throws <exception class>
* Description of criteria for throwing this exception.
*
* Write detailed description for operator >= here.
*
* \remarks
* Write remarks for operator >= here.
*
* \see
* Separate items with the '|' character.
*/
bool operator>=(const Texture&);
/*!
* \brief
* Write brief comment for operator > here.
*
* \param
* Description of parameter .
*
* \returns
* Write description of return value here.
*
* \throws <exception class>
* Description of criteria for throwing this exception.
*
* Write detailed description for operator > here.
*
* \remarks
* Write remarks for operator > here.
*
* \see
* Separate items with the '|' character.
*/
bool operator>(const Texture&);
private: private:
uint32_t minFilter; uint32_t minFilter;
@@ -339,5 +51,7 @@ class Texture {
std::string filename; std::string filename;
uint32_t id; uint32_t id;
}; };
extern Texture kUnknownTexture;
} // End namespace OpenArena } // End namespace OpenArena
#endif // End !defined(OpenArena__myglTexture_h__) #endif // End !defined(OpenArena__myglTexture_h__)

78
opengl.h Normal file
View File

@@ -0,0 +1,78 @@
/***************************************************************************
* Copyright (C) 2001-2023 by Tom Hicks *
* headhunter3@gmail.com *
* *
* 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 OpenArena__opengl_h__
#define OpenArena__opengl_h__
// clang-format off
#include "config.h"
#ifdef _WIN32
#include <windows.h>
#endif // End ifdef _WIN32
#if defined(__APPLE__)
#include <OpenGL/gl.h>
#include <OpenGL/glu.h>
#elif defined(_WIN32)
#include <GL/gl.h>
#include <GL/glu.h>
// link necessary libraries
#pragma comment(lib, "opengl32.lib")
#pragma comment(lib, "glu32.lib")
#pragma comment(lib, "kernel32.lib")
#pragma comment(lib, "user32.lib")
#pragma comment(lib, "gdi32.lib")
#pragma comment(lib, "advapi32.lib")
#pragma comment(lib, "winmm.lib")
#endif // defined __APPLE__
/*
#if defined USE_GLX
#include <GL/gl.h>
#include <GL/glu.h> //maybe not necessary
#include <GL/glx.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/keysym.h>
#if defined HAVE_XF86VIDMODE
#include <X11/extensions/xf86vmode.h>
#endif
#elif defined USE_AGL
#include <AGL/agl.h>
#include <OpenGL/gl.h>
#include <OpenGL/glu.h>
#elif defined USE_CGL
#include <OpenGL/OpenGL.h>
#include <OpenGL/gl.h>
#elif defined USE_WGL
#include <GL/gl.h>
#include <GL/glu.h>
#include <windows.h>
#endif
*/
// // define the function's prototype
// typedef void (*GL_GENBUFFERS) (GLsizei, GLuint*);
// // find the function and assign it to a function pointer
// GL_GENBUFFERS glGenBuffers = (GL_GENBUFFERS)wglGetProcAddress("glGenBuffers");
// // function can now be called as normal
// unsigned int buffer;
// glGenBuffers(1, &buffer);
#endif // End !defined(OpenArena__opengl_h__)

18
opengl/BUILD Normal file
View File

@@ -0,0 +1,18 @@
load("@rules_cc//cc:defs.bzl", "cc_library")
cc_library(
name = "window",
srcs = ["window.cpp"],
hdrs = ["window.h"],
visibility = ["//visibility:public"],
deps = ["//:window"],
)
cc_test(
name = "window_test",
srcs = ["window_test.cpp"],
deps = [
":window",
"@TinyTest//:tinytest",
],
)

486
opengl/window.cpp Normal file
View File

@@ -0,0 +1,486 @@
// clang-format off
#include "window.h"
#include <windows.h>
#include "..\opengl.h"
// clang-format on
namespace OpenArena {
namespace OpenGL {
namespace {
using OpenArena::Vec2i;
using std::string;
} // End namespace
void Window::SwapBuffers() {
#if defined USE_GLX
if (doubleBuffered) {
glXSwapBuffers(display, window);
}
#elif defined USE_AGL
aglSwapBuffers(_aglContext);
#elif defined USE_CGL
CGLFlushDrawable(cglContext);
#elif defined USE_WGL
::SwapBuffers(deviceContext);
#endif
}
bool Window::Open() {
#if defined USE_GLX
XVisualInfo* vi;
Colormap cmap;
int bestMode = 0;
int vidModeMajorVersion;
int vidModeMinorVersion;
int glxMajorVersion;
int glxMinorVersion;
int modeNum;
#if defined HAVE_XF86VIDMODE
XF86VidModeModeInfo** modes;
#endif
Atom wmDelete;
::Window winDummy;
unsigned int borderDummy;
display = XOpenDisplay(0);
screen = DefaultScreen(display);
#if defined HAVE_XF86VIDMODE
XF86VidModeQueryVersion(display, &vidModeMajorVersion, &vidModeMinorVersion);
printf("XF86VidModeExtension-Version %d.%d\n", vidModeMajorVersion, vidModeMinorVersion);
XF86VidModeGetAllModeLines(display, screen, &modeNum, &modes);
vidMode = *modes[0];
int i;
for (i = 0; i < modeNum; i++) {
// Add a check for colordepth here
if ((modes[i]->hdisplay == _width) && (modes[i]->vdisplay == _height)) {
bestMode = i;
}
}
#endif
vi = glXChooseVisual(display, screen, attrListDbl);
if (vi == NULL) {
vi = glXChooseVisual(display, screen, attrListSgl);
doubleBuffered = false;
printf("Only Singlebuffered Visual!\n");
} else {
doubleBuffered = true;
printf("Got Doublebuffered Visual!\n");
}
glXQueryVersion(display, &glxMajorVersion, &glxMinorVersion);
printf("glX-Version %d.%d\n", glxMajorVersion, glxMinorVersion);
hRC = glXCreateContext(display, vi, 0, GL_TRUE);
cmap = XCreateColormap(display, RootWindow(display, vi->screen), vi->visual, AllocNone);
attributes.colormap = cmap;
attributes.border_pixel = 0;
attributes.event_mask = ExposureMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask |
// PointerMotionMask | ButtonMotionMask |
StructureNotifyMask;
if (_fullscreen) {
#if defined HAVE_XF86VIDMODE
XF86VidModeSwitchToMode(display, screen, modes[bestMode]);
XF86VidModeSetViewPort(display, screen, 0, 0);
XFree(modes);
#endif
attributes.override_redirect = true;
window = XCreateWindow(display, RootWindow(display, vi->screen), 0, 0, _width, _height, 0, vi->depth, InputOutput,
vi->visual, CWBorderPixel | CWColormap | CWEventMask | CWOverrideRedirect, &attributes);
XWarpPointer(display, None, window, 0, 0, 0, 0, 0, 0);
XMapRaised(display, window);
XGrabKeyboard(display, window, true, GrabModeAsync, GrabModeAsync, CurrentTime);
XGrabPointer(display, window, true, ButtonPressMask, GrabModeAsync, GrabModeAsync, window, None, CurrentTime);
XDefineCursor(display, window, CreateFullscreenCursor());
} else {
window = XCreateWindow(display, RootWindow(display, vi->screen), 0, 0, _width, _height, 0, vi->depth, InputOutput,
vi->visual, CWBorderPixel | CWColormap | CWEventMask, &attributes);
wmDelete = XInternAtom(display, "WM_DELETE_WINDOW", true);
XSetWMProtocols(display, window, &wmDelete, 1);
XSetStandardProperties(display, window, GetName(), GetName(), None, NULL, 0, NULL);
XMapRaised(display, window);
XDefineCursor(display, window, CreateWindowedCursor());
}
glXMakeCurrent(display, window, hRC);
unsigned int twidth, theight, depth;
XGetGeometry(display, window, &winDummy, &x, &y, &twidth, &theight, &borderDummy, &depth);
_colorDepth = (char)depth;
_height = (short)twidth;
_width = (short)theight;
printf("Resolution %dx%d\n", twidth, theight);
printf("Depth %d\n", depth);
if (glXIsDirect(display, hRC)) {
printf("Congrats, you have Direct Rendering!\n");
} else {
printf("Sorry, no Direct Rendering possible!\n");
}
_initializer->Initialize();
return true;
#elif defined USE_AGL
OSStatus err = noErr;
SetRect(&_bounds, 0, 0, 640, 480);
err = CreateNewWindow(kDocumentWindowClass,
kWindowStandardHandlerAttribute | kWindowCloseBoxAttribute | kWindowFullZoomAttribute
| kWindowCollapseBoxAttribute,
&_bounds, &_window);
if (err != noErr) {
return false;
}
RepositionWindow(_window, NULL, kWindowCascadeOnMainScreen);
AGLDevice* devices = NULL;
GLint deviceCount = 0;
GLint attributes[] = {AGL_ACCELERATED, AGL_NO_RECOVERY, AGL_RGBA, AGL_DOUBLEBUFFER, AGL_NONE};
AGLPixelFormat pixelFormat;
pixelFormat = aglChoosePixelFormat(devices, deviceCount, attributes);
_aglContext = aglCreateContext(pixelFormat, NULL);
if (!_aglContext) {
exit(5);
}
aglDestroyPixelFormat(pixelFormat);
if (!aglSetCurrentContext(_aglContext)) {
exit(6);
}
if (!aglSetDrawable(_aglContext, GetWindowPort(_window))) {
exit(7);
}
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClear(GL_COLOR_BUFFER_BIT);
aglSwapBuffers(_aglContext);
ShowWindow(_window);
#elif defined USE_CGL
#error undefined method
#elif defined USE_WGL
unsigned int PixelFormat;
WNDCLASS wc;
DWORD dwExStyle;
DWORD dwStyle;
RECT WindowRect;
WindowRect.left = (long)0;
WindowRect.right = (long)_width;
WindowRect.top = (long)0;
WindowRect.bottom = (long)_height;
instance = GetModuleHandle(NULL);
wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
wc.lpfnWndProc = (WNDPROC)WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = instance;
wc.hIcon = LoadIcon(NULL, IDI_WINLOGO);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = NULL;
wc.lpszMenuName = NULL;
wc.lpszClassName = "OpenArena v0.1.0";
if (!RegisterClass(&wc)) {
MessageBox(NULL, "Failed To Register The Window Class.", "ERROR", MB_OK | MB_ICONEXCLAMATION);
return false;
}
if (_fullscreen) {
DEVMODE dmScreenSettings;
memset(&dmScreenSettings, 0, sizeof(dmScreenSettings));
dmScreenSettings.dmSize = sizeof(dmScreenSettings);
dmScreenSettings.dmPelsWidth = _width;
dmScreenSettings.dmPelsHeight = _height;
dmScreenSettings.dmBitsPerPel = _colorDepth;
dmScreenSettings.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
if (ChangeDisplaySettings(&dmScreenSettings, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL) {
if (MessageBox(NULL,
"The Requested Fullscreen Mode Is Not Supported By\nYour "
"Video Card. Use Windowed Mode Instead?",
"OpenArena", MB_YESNO | MB_ICONEXCLAMATION)
== IDYES)
_fullscreen = false;
else {
MessageBox(NULL, "Program Will Now Close.", "ERROR", MB_OK | MB_ICONSTOP);
return false;
}
}
}
if (_fullscreen) {
dwExStyle = WS_EX_APPWINDOW;
dwStyle = WS_POPUP;
ShowCursor(/*true*/ false);
} else {
ShowCursor(false);
dwExStyle = WS_EX_APPWINDOW | WS_EX_WINDOWEDGE;
dwStyle = WS_OVERLAPPEDWINDOW;
}
AdjustWindowRectEx(&WindowRect, dwStyle, false, dwExStyle);
if (!(window = CreateWindowEx(dwExStyle, "OpenArena v0.1.0", GetName(), WS_CLIPSIBLINGS | WS_CLIPCHILDREN | dwStyle,
0, 0, WindowRect.right - WindowRect.left, WindowRect.bottom - WindowRect.top, NULL,
NULL, instance, NULL))) {
Close();
MessageBox(NULL, "Window Creation Error.", "ERROR", MB_OK | MB_ICONEXCLAMATION);
return false;
}
static PIXELFORMATDESCRIPTOR pfd = {sizeof(PIXELFORMATDESCRIPTOR),
1,
PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER,
PFD_TYPE_RGBA,
static_cast<BYTE>(_colorDepth),
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
16,
0,
0,
PFD_MAIN_PLANE,
0,
0,
0,
0};
if (!(deviceContext = GetDC(window))) {
Close();
MessageBox(NULL, "Can't Create A GL Device Context.", "ERROR", MB_OK | MB_ICONEXCLAMATION);
return false;
}
if (!(PixelFormat = ChoosePixelFormat(deviceContext, &pfd))) {
Close();
MessageBox(NULL, "Can't Find A Suitable PixelFormat.", "ERROR", MB_OK | MB_ICONEXCLAMATION);
return false;
}
if (!SetPixelFormat(deviceContext, PixelFormat, &pfd)) {
Close();
MessageBox(NULL, "Can't Set The PixelFormat.", "ERROR", MB_OK | MB_ICONEXCLAMATION);
return false;
}
if (!(glContext = wglCreateContext(deviceContext))) {
Close();
MessageBox(NULL, "Can't Create A GL Rendering Context.", "ERROR", MB_OK | MB_ICONEXCLAMATION);
return false;
}
if (!wglMakeCurrent(deviceContext, glContext)) {
Close();
MessageBox(NULL, "Can't Activate The GL Rendering Context.", "ERROR", MB_OK | MB_ICONEXCLAMATION);
return false;
}
ShowWindow(window, SW_SHOW);
SetForegroundWindow(window);
SetFocus(window);
_resizer->Resize(_width, _height);
if (!_initializer->Initialize()) {
Close();
MessageBox(NULL, "Initialization Failed.", "ERROR", MB_OK | MB_ICONEXCLAMATION);
return false;
}
return true;
#endif
return false;
}
void Window::Close() {
#if defined USE_GLX
if (_fullscreen) {
#if defined HAVE_XF86VIDMODE
XF86VidModeSwitchToMode(display, screen, &vidMode);
XF86VidModeSetViewPort(display, screen, 0, 0);
#endif
}
if (hRC) {
if (!glXMakeCurrent(display, None, NULL)) {
printf("Could not release drawing context.\n");
}
glXDestroyContext(display, hRC);
hRC = NULL;
}
XCloseDisplay(display);
#elif defined USE_AGL
if (!_fullscreen) {
aglSetCurrentContext(NULL);
aglDestroyContext(_aglContext);
_aglContext = NULL;
}
#elif defined USE_CGL
#error unimplemented method
#elif defined USE_WGL
if (_fullscreen) {
ChangeDisplaySettings(NULL, 0);
ShowCursor(true);
}
if (glContext) {
if (!wglMakeCurrent(NULL, NULL))
MessageBox(NULL, "Release Of DC And RC Failed.", "SHUTDOWN ERROR", MB_OK | MB_ICONINFORMATION);
if (!wglDeleteContext(glContext))
MessageBox(NULL, "Release Rendering Context Failed.", "SHUTDOWN ERROR", MB_OK | MB_ICONINFORMATION);
glContext = NULL;
}
if (deviceContext && !ReleaseDC(window, deviceContext)) {
MessageBox(NULL, "Release Device Context Failed.", "SHUTDOWN ERROR", MB_OK | MB_ICONINFORMATION);
deviceContext = NULL;
}
if (window && !DestroyWindow(window)) {
MessageBox(NULL, "Could Not Release hWnd.", "SHUTDOWN ERROR", MB_OK | MB_ICONINFORMATION);
window = NULL;
}
if (!UnregisterClass("OpenArena v0.1.0", instance)) {
MessageBox(NULL, "Could Not Unregister Class.", "SHUTDOWN ERROR", MB_OK | MB_ICONINFORMATION);
instance = NULL;
}
#endif
}
bool Window::Open(string title, int width, int height, int bits, bool fullscreenflag) {
_fullscreen = fullscreenflag;
_width = width;
_height = height;
_colorDepth = bits;
_name = title;
return Open();
}
Window::Window() {
_initializer = new Initializer();
_resizer = new Resizer();
}
Window::~Window() {}
void Window::SetInitializer(Window::Initializer* initializer) {
_initializer = initializer;
}
void Window::SetResizer(Window::Resizer* resizer) {
_resizer = resizer;
}
void Window::Resizer::Resize(uint32_t width, uint32_t height) {
if (height == 0) height = 1;
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0f, (float)width / (float)height, 0.1f, 100.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
int Window::Initializer::Initialize() {
glEnable(GL_TEXTURE_2D);
glShadeModel(GL_SMOOTH);
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClearDepth(1.0f);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
return true;
}
void Window::Resize(uint32_t width, uint32_t height) {
_resizer->Resize(width, height);
}
Vec2i Window::GetMousePosition() {
#ifdef USE_GLX
::Window rootWindow;
::Window childWindow;
int rootX;
int rootY;
int mouseX;
int mouseY;
unsigned int mask;
if (!XQueryPointer(display, window, &rootWindow, &childWindow, &rootX, &rootY, &mouseX, &mouseY, &mask)) {
return Vec2i(-1, -1);
} else {
return Vec2i(mouseX, mouseY);
}
#elif defined USE_AGL
#warning unimplemented method
#elif defined USE_CGL
#error unimplemented method
#elif defined USE_WGL
POINT pos;
GetCursorPos(&pos);
return Vec2i(pos.x, pos.y);
#else
return Vec2i(0, 0);
#endif
}
void Window::SetMousePosition(Vec2i pos) {
#if defined USE_GLX
XWarpPointer(display, None, window, 0, 0, 0, 0, pos.x, pos.y);
#elif defined USE_AGL
#warning unimplemented method
#elif defined USE_CGL
#error unimplemented method
#elif defined USE_WGL
SetCursorPos(pos.x, pos.y);
#endif
}
#ifdef USE_GLX
Display* Window::GetDisplay() {
return display;
}
Cursor Window::CreateWindowedCursor() {
return CreateFullscreenCursor();
}
Cursor OpenArena::Window::CreateFullscreenCursor() {
Pixmap pixmap = XCreatePixmap(display, window, 1, 1, 1);
XColor color;
color.pixel = 0;
color.red = 0;
color.flags = DoRed;
Cursor cur = XCreatePixmapCursor(display, pixmap, pixmap, &color, &color, 0, 0);
XFreePixmap(display, pixmap);
return cur;
}
#endif
} // End namespace OpenGL
} // End namespace OpenArena

67
opengl/window.h Normal file
View File

@@ -0,0 +1,67 @@
// clang-format off
#include "../config.h"
#include "../window.h"
// clang-format on
#ifdef USE_OPENGL
namespace OpenArena {
namespace OpenGL {
class Window : public ::OpenArena::Window {
public:
class Resizer : public ::OpenArena::Window::Resizer {
public:
void Resize(uint32_t width, uint32_t height);
};
class Initializer : public ::OpenArena::Window::Initializer {
public:
int Initialize();
};
Window();
virtual ~Window();
virtual void Close();
virtual bool Open();
virtual bool Open(std::string title, int width, int height, int bits,
bool fullscreenflag); // make that string a const char* after this works
virtual void SetInitializer(Initializer* initializer);
virtual void SetResizer(Resizer* resizer);
virtual void SwapBuffers();
virtual void Resize(uint32_t width, uint32_t height);
virtual Vec2i GetMousePosition();
virtual void SetMousePosition(Vec2i pos);
private:
#ifdef USE_GLX
Cursor CreateWindowedCursor();
Cursor CreateFullscreenCursor();
int screen;
::Window window;
GLXContext hRC;
XSetWindowAttributes attributes;
bool doubleBuffered;
#if defined HAVE_XF86VIDMODE
XF86VidModeModeInfo vidMode;
#endif
int x, y;
Display* display;
#elif defined USE_AGL
AGLContext _aglContext;
WindowRef _window;
Rect _bounds;
#elif defined USE_WGL
// TODO: move this to opengl/window
HGLRC glContext;
HWND window;
HDC deviceContext;
HINSTANCE instance;
#endif
Resizer* _resizer;
Initializer* _initializer;
};
} // namespace OpenGL
} // namespace OpenArena
#ifdef USE_WGL
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
#endif
#endif

22
opengl/window_test.cpp Normal file
View File

@@ -0,0 +1,22 @@
#include <tinytest.h>
#include <iostream>
namespace {
using std::cout;
using TinyTest::TestResults;
} // namespace
TestResults test_something() {
return TestResults().Pass();
}
int main(int argc, char* argv[]) {
TestResults results;
results += test_something();
PrintResults(cout, results);
return results.Failed() + results.Errors();
}

View File

@@ -17,8 +17,12 @@
* Free Software Foundation, Inc., * * Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/ ***************************************************************************/
// clang-format off
#include "player.h" #include "player.h"
// clang-format on
namespace OpenArena { namespace OpenArena {
void Player::Load() {} void Player::Load() {}

View File

@@ -17,17 +17,17 @@
* Free Software Foundation, Inc., * * Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/ ***************************************************************************/
#ifndef OpenArena__player_h__ #ifndef OpenArena__player_h__
#define OpenArena__player_h__ #define OpenArena__player_h__
// clang-format off
#if defined HAVE_CONFIG_H
#include "config.h" #include "config.h"
#endif
#include "EventManager.h" #include "EventManager.h"
#include "camera.h" #include "camera.h"
#include "ctrls.h" #include "ctrls.h"
// clang-format on
namespace OpenArena { namespace OpenArena {
class Player { class Player {
public: public:

View File

@@ -17,9 +17,17 @@
* Free Software Foundation, Inc., * * Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/ ***************************************************************************/
// clang-format off
#include "screen.h" #include "screen.h"
// clang-format on
namespace OpenArena { namespace OpenArena {
namespace {
using std::string;
} // End namespace
Screen::Screen() { Screen::Screen() {
_width = 640; _width = 640;
_height = 480; _height = 480;

275
screen.h
View File

@@ -17,302 +17,39 @@
* Free Software Foundation, Inc., * * Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/ ***************************************************************************/
#ifndef OpenArena__screen_h__ #ifndef OpenArena__screen_h__
#define OpenArena__screen_h__ #define OpenArena__screen_h__
// clang-format off
#include "config.h"
#include <string> #include <string>
#if defined HAVE_CONFIG_H // clang-format on
#include "config.h"
#endif
using namespace std;
namespace OpenArena { namespace OpenArena {
/*!
* \brief
* Write brief comment for Screen here.
*
* Write detailed description for Screen here.
*
* \remarks
* Write remarks for Screen here.
*
* \see
* Separate items with the '|' character.
*/
class Screen { class Screen {
public: public:
/*!
* \brief
* Write brief comment for Screen here.
*
* \throws <exception class>
* Description of criteria for throwing this exception.
*
* Write detailed description for Screen here.
*
* \remarks
* Write remarks for Screen here.
*
* \see
* Separate items with the '|' character.
*/
Screen(); Screen();
/*!
* \brief
* Write brief comment for GetWidth here.
*
* \returns
* Write description of return value here.
*
* \throws <exception class>
* Description of criteria for throwing this exception.
*
* Write detailed description for GetWidth here.
*
* \remarks
* Write remarks for GetWidth here.
*
* \see
* Separate items with the '|' character.
*/
int GetWidth(); int GetWidth();
/*!
* \brief
* Write brief comment for GetHeight here.
*
* \returns
* Write description of return value here.
*
* \throws <exception class>
* Description of criteria for throwing this exception.
*
* Write detailed description for GetHeight here.
*
* \remarks
* Write remarks for GetHeight here.
*
* \see
* Separate items with the '|' character.
*/
int GetHeight(); int GetHeight();
/*!
* \brief
* Write brief comment for GetColorDepth here.
*
* \returns
* Write description of return value here.
*
* \throws <exception class>
* Description of criteria for throwing this exception.
*
* Write detailed description for GetColorDepth here.
*
* \remarks
* Write remarks for GetColorDepth here.
*
* \see
* Separate items with the '|' character.
*/
int GetColorDepth(); int GetColorDepth();
/*!
* \brief
* Write brief comment for GetFullscreen here.
*
* \returns
* Write description of return value here.
*
* \throws <exception class>
* Description of criteria for throwing this exception.
*
* Write detailed description for GetFullscreen here.
*
* \remarks
* Write remarks for GetFullscreen here.
*
* \see
* Separate items with the '|' character.
*/
bool GetFullscreen(); bool GetFullscreen();
/*!
* \brief
* Write brief comment for GetName here.
*
* \returns
* Write description of return value here.
*
* \throws <exception class>
* Description of criteria for throwing this exception.
*
* Write detailed description for GetName here.
*
* \remarks
* Write remarks for GetName here.
*
* \see
* Separate items with the '|' character.
*/
const char* GetName(); const char* GetName();
/*!
* \brief
* Write brief comment for SetWidth here.
*
* \param
* Description of parameter .
*
* \throws <exception class>
* Description of criteria for throwing this exception.
*
* Write detailed description for SetWidth here.
*
* \remarks
* Write remarks for SetWidth here.
*
* \see
* Separate items with the '|' character.
*/
void SetWidth(int); void SetWidth(int);
/*!
* \brief
* Write brief comment for SetHeight here.
*
* \param
* Description of parameter .
*
* \throws <exception class>
* Description of criteria for throwing this exception.
*
* Write detailed description for SetHeight here.
*
* \remarks
* Write remarks for SetHeight here.
*
* \see
* Separate items with the '|' character.
*/
void SetHeight(int); void SetHeight(int);
/*!
* \brief
* Write brief comment for Resize here.
*
* \param
* Description of parameter .
*
* \param
* Description of parameter .
*
* \throws <exception class>
* Description of criteria for throwing this exception.
*
* Write detailed description for Resize here.
*
* \remarks
* Write remarks for Resize here.
*
* \see
* Separate items with the '|' character.
*/
void Resize(int, int); void Resize(int, int);
/*!
* \brief
* Write brief comment for SetColorDepth here.
*
* \param
* Description of parameter .
*
* \throws <exception class>
* Description of criteria for throwing this exception.
*
* Write detailed description for SetColorDepth here.
*
* \remarks
* Write remarks for SetColorDepth here.
*
* \see
* Separate items with the '|' character.
*/
void SetColorDepth(int); void SetColorDepth(int);
/*!
* \brief
* Write brief comment for SetFullscreen here.
*
* \param
* Description of parameter .
*
* \throws <exception class>
* Description of criteria for throwing this exception.
*
* Write detailed description for SetFullscreen here.
*
* \remarks
* Write remarks for SetFullscreen here.
*
* \see
* Separate items with the '|' character.
*/
void SetFullscreen(bool); void SetFullscreen(bool);
/*!
* \brief
* Write brief comment for ToggleFullscreen here.
*
* \throws <exception class>
* Description of criteria for throwing this exception.
*
* Write detailed description for ToggleFullscreen here.
*
* \remarks
* Write remarks for ToggleFullscreen here.
*
* \see
* Separate items with the '|' character.
*/
void ToggleFullscreen(); void ToggleFullscreen();
/*!
* \brief
* Write brief comment for SetName here.
*
* \param
* Description of parameter .
*
* \throws <exception class>
* Description of criteria for throwing this exception.
*
* Write detailed description for SetName here.
*
* \remarks
* Write remarks for SetName here.
*
* \see
* Separate items with the '|' character.
*/
void SetName(const char*); void SetName(const char*);
/*! void SetName(std::string);
* \brief
* Write brief comment for SetName here.
*
* \param
* Description of parameter .
*
* \throws <exception class>
* Description of criteria for throwing this exception.
*
* Write detailed description for SetName here.
*
* \remarks
* Write remarks for SetName here.
*
* \see
* Separate items with the '|' character.
*/
void SetName(string);
protected: protected:
short _width; short _width;
short _height; short _height;
char _colorDepth; char _colorDepth;
bool _fullscreen; bool _fullscreen;
// public: std::string _name;
string _name;
}; };
} // End namespace OpenArena } // End namespace OpenArena
#endif // End !defined(OpenArena__screen_h__) #endif // End !defined(OpenArena__screen_h__)

View File

@@ -17,12 +17,18 @@
* Free Software Foundation, Inc., * * Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/ ***************************************************************************/
// clang-format off
#include "strmanip.h" #include "strmanip.h"
#include <cctype> #include <cctype>
#include "keys.h" #include "keys.h"
// clang-format on
namespace {
using std::string;
} // End namespace
bool Truth(std::string str) { bool Truth(std::string str) {
if (toupper(str[0]) == 'T' || str[0] == '1') if (toupper(str[0]) == 'T' || str[0] == '1')
return true; return true;

View File

@@ -17,221 +17,24 @@
* Free Software Foundation, Inc., * * Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/ ***************************************************************************/
#ifndef OpenArena__strmanip_h__ #ifndef OpenArena__strmanip_h__
#define OpenArena__strmanip_h__ #define OpenArena__strmanip_h__
// clang-format off
#if defined HAVE_CONFIG_H
#include "config.h" #include "config.h"
#endif
#include <cmath> #include <cmath>
#include <string> #include <string>
// clang-format on
using namespace std; bool Truth(std::string str);
int Integer(std::string str);
float Floating(std::string str);
/*! std::string KeyString(uint8_t keyCode);
* \brief std::string Right(std::string, uint32_t);
* Write brief comment for Truth here. std::string Left(std::string, uint32_t);
* std::string tolower(std::string);
* \param str std::string toupper(std::string);
* Description of parameter str. std::string word(std::string, uint32_t);
*
* \returns
* Write description of return value here.
*
* \throws <exception class>
* Description of criteria for throwing this exception.
*
* Write detailed description for Truth here.
*
* \remarks
* Write remarks for Truth here.
*
* \see
* Separate items with the '|' character.
*/
bool Truth(string str);
/*!
* \brief
* Write brief comment for Integer here.
*
* \param str
* Description of parameter str.
*
* \returns
* Write description of return value here.
*
* \throws <exception class>
* Description of criteria for throwing this exception.
*
* Write detailed description for Integer here.
*
* \remarks
* Write remarks for Integer here.
*
* \see
* Separate items with the '|' character.
*/
int Integer(string str);
/*!
* \brief
* Write brief comment for Floating here.
*
* \param str
* Description of parameter str.
*
* \returns
* Write description of return value here.
*
* \throws <exception class>
* Description of criteria for throwing this exception.
*
* Write detailed description for Floating here.
*
* \remarks
* Write remarks for Floating here.
*
* \see
* Separate items with the '|' character.
*/
float Floating(string str);
/**
* @brief
* Write brief comment for KeyString here.
*
* @param keyCode - Description of parameter .
*
* @returns
* Write description of return value here.
*
* Write detailed description for KeyString here.
*
* @remarks
* Write remarks for KeyString here.
*
* @see
* Separate items with the '|' character.
*/
string KeyString(uint8_t keyCode);
/*!
* @brief
* Write brief comment for Right here.
*
* @param
* Description of parameter .
*
* @param
* Description of parameter .
*
* @returns
* Write description of return value here.
*
* @throws <exception class>
* Description of criteria for throwing this exception.
*
* Write detailed description for Right here.
*
* @remarks
* Write remarks for Right here.
*
* @see
* Separate items with the '|' character.
*/
string Right(string, uint32_t);
/*!
* @brief
* Write brief comment for Left here.
*
* @param
* Description of parameter .
*
* @param
* Description of parameter .
*
* @returns
* Write description of return value here.
*
* @throws <exception class>
* Description of criteria for throwing this exception.
*
* Write detailed description for Left here.
*
* @remarks
* Write remarks for Left here.
*
* @see
* Separate items with the '|' character.
*/
string Left(string, uint32_t);
/*!
* \brief
* Write brief comment for tolower here.
*
* \param
* Description of parameter .
*
* \returns
* Write description of return value here.
*
* \throws <exception class>
* Description of criteria for throwing this exception.
*
* Write detailed description for tolower here.
*
* \remarks
* Write remarks for tolower here.
*
* \see
* Separate items with the '|' character.
*/
string tolower(string);
/*!
* \brief
* Write brief comment for toupper here.
*
* \param
* Description of parameter .
*
* \returns
* Write description of return value here.
*
* \throws <exception class>
* Description of criteria for throwing this exception.
*
* Write detailed description for toupper here.
*
* \remarks
* Write remarks for toupper here.
*
* \see
* Separate items with the '|' character.
*/
string toupper(string);
/*!
* \brief
* Write brief comment for word here.
*
* \param
* Description of parameter .
*
* \param
* Description of parameter .
*
* \returns
* Write description of return value here.
*
* \throws <exception class>
* Description of criteria for throwing this exception.
*
* Write detailed description for word here.
*
* \remarks
* Write remarks for word here.
*
* \see
* Separate items with the '|' character.
*/
string word(string, uint32_t);
#endif // End !defined(OpenArena__strmanip_h__) #endif // End !defined(OpenArena__strmanip_h__)

17
temp.cpp Normal file
View File

@@ -0,0 +1,17 @@
#include <iostream>
#using namespace std;
class Logger {
static void LogDebug(const string& message) { cout << message << endl; }
static void LogUnimplementedMethodReal(const string& method_name) {
LogDebug("Unimplemented method: " + method_name);
}
}
#define LogUnimplementedMethod Logger::LogUnimplementedMethodReal(__FUNCTION__)
int main (int argc, char* argv[]) {
Logger::LogUnimplementedMethod;
return 0;
}

View File

@@ -17,26 +17,15 @@
* Free Software Foundation, Inc., * * Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/ ***************************************************************************/
#ifndef OpenArena__texture_h__ #ifndef OpenArena__texture_h__
#define OpenArena__texture_h__ #define OpenArena__texture_h__
// clang-format off
#if defined HAVE_CONFIG_H
#include "config.h" #include "config.h"
#endif
// clang-format on
namespace OpenArena { namespace OpenArena {
/*!
* \brief
* Write brief comment for TextureImage here.
*
* Write detailed description for TextureImage here.
*
* \remarks
* Write remarks for TextureImage here.
*
* \see
* Separate items with the '|' character.
*/
class TextureImage { class TextureImage {
public: public:
unsigned char* data; unsigned char* data;

748
tga.cpp
View File

@@ -17,631 +17,221 @@
* Free Software Foundation, Inc., * * Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/ ***************************************************************************/
// clang-format off
#include "tga.h" #include "tga.h"
#include <OpenGL/gl.h> #include <cstdio>
#include <memory>
#include <string>
#ifdef WIN32 #include "Logger.h"
#pragma warning(disable : 4996) #include "opengl.h"
#endif
// clang-format on
namespace OpenArena { namespace OpenArena {
TextureImage* LoadTGA(const char* filename) { namespace {
TGAHeader tgaheader; using std::make_shared;
TextureImage* image; using std::shared_ptr;
std::string errmsg; using std::string;
FILE* file = fopen(filename, "rb");
if (file == NULL) { struct TGAHeader {
errmsg = "Could not open texture file "; uint8_t Header[12]; // File Header To Determine File Type
errmsg = errmsg + filename; };
// This needs to be abstracted somehow
#ifdef WIN32 struct TGA {
MessageBox(NULL, errmsg.c_str(), "ERROR", MB_OK); uint8_t header[6]; // Holds The First 6 Useful Bytes Of The File
#endif uint32_t bytesPerPixel; // Number Of BYTES Per Pixel (3 Or 4)
return NULL; uint32_t imageSize; // Amount Of Memory Needed To Hold The Image
uint32_t type; // The Type Of Image, GL_RGB Or GL_RGBA
uint32_t Height; // Height Of Image
uint32_t Width; // Width Of Image
uint32_t Bpp; // Number Of BITS Per Pixel (24 Or 32)
};
const uint8_t uTGAcompare[12] = {0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0}; // Uncompressed TGA Header
const uint8_t cTGAcompare[12] = {0, 0, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0}; // Compressed TGA Header
} // End namespace
shared_ptr<TargaImage> LoadUncompressedTGA(FILE*); // Load an Uncompressed file
shared_ptr<TargaImage> LoadCompressedTGA(FILE*); // Load a Compressed file
TargaImage::~TargaImage() {}
shared_ptr<TargaImage> TargaImage::FromFile(string filename) {
const string method_name = "OpenArena::TargaImage::FromFile(string) ";
FILE* file = nullptr;
TGAHeader tga_header;
if (filename.empty()) {
Logger::LogError(method_name + "filename is empty");
return nullptr;
} }
if (fread(&tgaheader, sizeof(TGAHeader), 1, file) == 0) { // TODO: If our filename doesn't exist return null.
// This needs to be abstracted somehow
#ifdef WIN32 fopen_s(&file, filename.c_str(), "rb");
MessageBox(NULL, "Could not read file header", "ERROR", MB_OK); if (file == nullptr) {
#endif Logger::LogError(method_name + "unable to open file " + filename);
if (file != NULL) fclose(file); return nullptr;
return NULL;
} }
if (memcmp(uTGAcompare, &tgaheader, sizeof(tgaheader)) == 0) if (fread(&tga_header, sizeof(tga_header), 1, file) != 1) {
image = LoadUncompressedTGA(file); Logger::LogError(method_name + "Could not read file header from file " + filename);
else if (memcmp(cTGAcompare, &tgaheader, sizeof(tgaheader)) == 0)
image = LoadCompressedTGA(file);
else {
// This needs to be abstracted somehow
#ifdef WIN32
MessageBox(NULL, "TGA file must be type 2 or type 10 ", "Invalid Image", MB_OK);
#endif
fclose(file); fclose(file);
return NULL; return nullptr;
}
return image;
}
TextureImage* LoadUncompressedTGA(FILE* fTGA) {
TGA tga;
TextureImage* image = new TextureImage;
if (fread(tga.header, sizeof(tga.header), 1, fTGA) == 0) {
// This needs to be abstracted somehow
#ifdef WIN32
MessageBox(NULL, "Could not read info header", "ERROR", MB_OK);
#endif
if (fTGA != NULL) {
fclose(fTGA);
}
return NULL;
} }
image->sizeY = tga.header[1] * 256 + tga.header[0]; if (memcmp(uTGAcompare, &tga_header, sizeof(tga_header)) == 0) {
image->sizeX = tga.header[3] * 256 + tga.header[2]; return LoadUncompressedTGA(file);
image->bpp = tga.header[4]; } else if (memcmp(cTGAcompare, &tga_header, sizeof(tga_header)) == 0) {
tga.Width = image->sizeX; return LoadCompressedTGA(file);
tga.Height = image->sizeY;
tga.Bpp = image->bpp;
if ((image->sizeX <= 0) || (image->sizeY <= 0) || ((image->bpp != 24) && (image->bpp != 32))) {
// This needs to be abstracted somehow
#ifdef WIN32
MessageBox(NULL, "Invalid texture information", "ERROR", MB_OK);
#endif
if (fTGA != NULL) {
fclose(fTGA);
}
return NULL;
}
if (image->bpp == 24) {
image->type = GL_RGB;
} else { } else {
image->type = GL_RGBA; Logger::LogError(method_name + "TGA file must be type 2 or type 10");
fclose(file);
return nullptr;
}
}
shared_ptr<TargaImage> LoadUncompressedTGA(FILE* file) {
const string method_name = "OpenArena::TargaImage::<anonymous>::LoadUncompressedTGA(FILE*)";
TGA tga;
shared_ptr<TargaImage> image = make_shared<TargaImage>();
if (fread(tga.header, sizeof(tga.header), 1, file) != 1) {
Logger::LogError(method_name + "Cound not read info header");
fclose(file);
return nullptr;
} }
tga.bytesPerPixel = (tga.Bpp / 8); image->bpp_ = tga.header[4];
tga.imageSize = (tga.bytesPerPixel * tga.Width * tga.Height); image->size_x_ = tga.header[3] * 256 + tga.header[2];
image->data = (uint8_t*)malloc(tga.imageSize); image->size_y_ = tga.header[1] * 256 + tga.header[0];
if (image->data == NULL) { if ((image->size_x_ <= 0) || (image->size_y_ <= 0) || ((image->bpp_ != 24) && (image->bpp_ != 32))) {
// This needs to be abstracted somehow Logger::LogError(method_name + "Invalid texture information");
#ifdef WIN32 fclose(file);
MessageBox(NULL, "Could not allocate memory for image", "ERROR", MB_OK); return nullptr;
#endif
fclose(fTGA);
return NULL;
} }
if (fread(image->data, 1, tga.imageSize, fTGA) != tga.imageSize) { if (image->bpp_ == 24) {
// This needs to be abstracted somehow image->type_ = ImageBase::Type::RGB;
#ifdef WIN32 } else {
MessageBox(NULL, "Could not read image data", "ERROR", MB_OK); image->type_ = ImageBase::Type::RGBA;
#endif
if (image->data != NULL) {
free(image->data);
}
fclose(fTGA);
return NULL;
} }
for (uint32_t cswap = 0; cswap < (int)tga.imageSize; cswap += tga.bytesPerPixel) { int bytes_per_pixel = image->bpp_ / 8;
image->data[cswap] ^= image->data[cswap + 2] ^= image->data[cswap] ^= image->data[cswap + 2]; int num_pixels = image->size_x_ * image->size_y_;
int num_bytes = num_pixels * bytes_per_pixel;
image->data_ = shared_ptr<uint8_t[]>(new uint8_t[num_bytes]);
if (image->data_ == nullptr) {
Logger::LogError(method_name + "Could not allocate memory for image");
fclose(file);
return nullptr;
} }
fclose(fTGA); if (fread(image->data_.get(), 1, num_bytes, file) != num_bytes) {
Logger::LogError(method_name + "Could not read image data");
fclose(file);
return nullptr;
}
for (uint32_t cswap = 0; cswap < num_bytes; cswap += bytes_per_pixel) {
image->data_[cswap] ^= image->data_[cswap + 2] ^= image->data_[cswap] ^= image->data_[cswap + 2];
}
fclose(file);
return image; return image;
} }
TextureImage* LoadCompressedTGA(FILE* fTGA) { shared_ptr<TargaImage> LoadCompressedTGA(FILE* file) {
TextureImage* image = new TextureImage; const std::string method_name = "OpenArena::TargaImage::<anonymous>::LoadCompressedTGA ";
shared_ptr<TargaImage> image = make_shared<TargaImage>();
TGA tga; TGA tga;
if (fread(tga.header, sizeof(tga.header), 1, fTGA) == 0) { if (fread(tga.header, sizeof(tga.header), 1, file) != 1) {
// This needs to be abstracted somehow Logger::LogError(method_name + "Could not read info header");
#ifdef WIN32 fclose(file);
MessageBox(NULL, "Could not read info header", "ERROR", MB_OK); return nullptr;
#endif
if (fTGA != NULL) {
fclose(fTGA);
}
return NULL;
} }
image->sizeX = tga.header[1] * 256 + tga.header[0]; image->bpp_ = tga.header[4];
image->sizeY = tga.header[3] * 256 + tga.header[2]; image->size_x_ = tga.header[1] * 256 + tga.header[0];
image->bpp = tga.header[4]; image->size_y_ = tga.header[3] * 256 + tga.header[2];
tga.Width = image->sizeX;
tga.Height = image->sizeY;
tga.Bpp = image->bpp;
if ((image->sizeX <= 0) || (image->sizeY <= 0) || ((image->bpp != 24) && (image->bpp != 32))) { if ((image->size_x_ <= 0) || (image->size_y_ <= 0) || ((image->bpp_ != 24) && (image->bpp_ != 32))) {
// This needs to be abstracted somehow Logger::LogError(method_name + "Invalid texture information");
#ifdef WIN32 fclose(file);
MessageBox(NULL, "Invalid texture information", "ERROR", MB_OK); return nullptr;
#endif
if (fTGA != NULL) {
fclose(fTGA);
}
return NULL;
} }
int bytes_per_pixel = image->bpp_ / 8;
tga.bytesPerPixel = (tga.Bpp / 8); int num_pixels = image->size_x_ * image->size_y_;
tga.imageSize = (tga.bytesPerPixel * tga.Width * tga.Height); int num_bytes = num_pixels * bytes_per_pixel;
image->data = (uint8_t*)malloc(tga.imageSize); image->data_ = shared_ptr<uint8_t[]>(new uint8_t[num_bytes]);
if (image->data_ == nullptr) {
if (image->data == NULL) { Logger::LogError(method_name + "Could not allocate memory for image");
// This needs to be abstracted somehow fclose(file);
#ifdef WIN32 return nullptr;
MessageBox(NULL, "Could not allocate memory for image", "ERROR", MB_OK);
#endif
fclose(fTGA);
return NULL;
} }
// TODO: Abstract the RLE decoder to it's own file/class.
uint32_t pixelcount = tga.Height * tga.Width; uint32_t current_pixel = 0;
uint32_t currentpixel = 0; uint32_t current_byte = 0;
uint32_t currentbyte = 0; uint8_t* color_buffer = (uint8_t*)malloc(bytes_per_pixel);
uint8_t* colorbuffer = (uint8_t*)malloc(tga.bytesPerPixel);
do { do {
uint8_t chunkheader = 0; uint8_t chunk_header = 0;
if (fread(&chunk_header, sizeof(uint8_t), 1, file) != 1) {
if (fread(&chunkheader, sizeof(uint8_t), 1, fTGA) == 0) { Logger::LogError(method_name + "Could not read RLE header");
// This needs to be abstracted somehow fclose(file);
#ifdef WIN32 return nullptr;
MessageBox(NULL, "Could not read RLE header", "ERROR", MB_OK);
#endif
if (fTGA != NULL) {
fclose(fTGA);
}
if (image->data != NULL) {
free(image->data);
}
return NULL;
} }
if (chunkheader < 128) { if (chunk_header < 128) {
chunkheader++; chunk_header++;
for (short counter = 0; counter < chunkheader; counter++) { for (uint16_t counter = 0; counter < chunk_header; counter++) {
if (fread(colorbuffer, 1, tga.bytesPerPixel, fTGA) != tga.bytesPerPixel) { if (fread(color_buffer, 1, bytes_per_pixel, file) != bytes_per_pixel) {
// This needs to be abstracted somehow Logger::LogError(method_name + "Could not read image data.");
#ifdef WIN32 fclose(file);
MessageBox(NULL, "Could not read image data", "ERROR", MB_OK); return nullptr;
#endif
if (fTGA != NULL) {
fclose(fTGA);
}
if (colorbuffer != NULL) {
free(colorbuffer);
}
if (image->data != NULL) {
free(image->data);
}
return NULL;
} }
image->data_[current_byte] = color_buffer[2];
image->data[currentbyte] = colorbuffer[2]; image->data_[current_byte + 1] = color_buffer[1];
image->data[currentbyte + 1] = colorbuffer[1]; image->data_[current_byte + 2] = color_buffer[0];
image->data[currentbyte + 2] = colorbuffer[0]; if (bytes_per_pixel == 4) {
image->data_[current_byte + 3] = color_buffer[3];
if (tga.bytesPerPixel == 4) {
image->data[currentbyte + 3] = colorbuffer[3];
} }
current_byte += bytes_per_pixel;
currentbyte += tga.bytesPerPixel; current_pixel++;
currentpixel++; if (current_pixel > num_pixels) {
Logger::LogError(method_name + "Too many pixels read.");
if (currentpixel > pixelcount) { fclose(file);
// This needs to be abstracted somehow
#ifdef WIN32
MessageBox(NULL, "Too many pixels read", "ERROR", NULL);
#endif
if (fTGA != NULL) {
fclose(fTGA);
}
if (colorbuffer != NULL) {
free(colorbuffer);
}
if (image->data != NULL) {
free(image->data);
}
return NULL;
} }
} }
} else { } else {
chunkheader -= 127; chunk_header -= 127;
if (fread(colorbuffer, 1, tga.bytesPerPixel, fTGA) != tga.bytesPerPixel) { if (fread(color_buffer, 1, bytes_per_pixel, file) != bytes_per_pixel) {
// This needs to be abstracted somehow Logger::LogError(method_name + "Could not read from file.");
#ifdef WIN32 fclose(file);
MessageBox(NULL, "Could not read from file", "ERROR", MB_OK); return nullptr;
#endif
if (fTGA != NULL) {
fclose(fTGA);
}
if (colorbuffer != NULL) {
free(colorbuffer);
}
if (image->data != NULL) {
free(image->data);
}
return NULL;
} }
for (uint16_t counter = 0; counter < chunk_header; counter++) {
for (short counter = 0; counter < chunkheader; counter++) { image->data_[current_byte] = color_buffer[2];
image->data[currentbyte] = colorbuffer[2]; image->data_[current_byte + 1] = color_buffer[1];
image->data[currentbyte + 1] = colorbuffer[1]; image->data_[current_byte + 2] = color_buffer[0];
image->data[currentbyte + 2] = colorbuffer[0]; if (bytes_per_pixel == 4) {
image->data_[current_byte + 3] = color_buffer[3];
if (tga.bytesPerPixel == 4) {
image->data[currentbyte + 3] = colorbuffer[3];
} }
current_byte += bytes_per_pixel;
currentbyte += tga.bytesPerPixel; current_pixel++;
currentpixel++; if (current_pixel > num_pixels) {
Logger::LogError(method_name + "Too many pixels read.");
if (currentpixel > pixelcount) { fclose(file);
// This needs to be abstracted somehow return nullptr;
#ifdef WIN32
MessageBox(NULL, "Too many pixels read", "ERROR", NULL);
#endif
if (fTGA != NULL) {
fclose(fTGA);
}
if (colorbuffer != NULL) {
free(colorbuffer);
}
if (image->data != NULL) {
free(image->data);
}
return NULL;
} }
} }
} }
} } while (current_pixel < num_pixels);
fclose(file);
while (currentpixel < pixelcount);
fclose(fTGA);
return image; return image;
} }
/*
TextureImage* LoadTGA(const char * filename)
{
TGAHeader tgaheader;
TextureImage* image;
std::string errmsg;
FILE* file = fopen(filename, "rb");
if(file == NULL)
{
errmsg = "Could not open texture file ";
errmsg = errmsg + filename;
MessageBox(NULL, errmsg.c_str(), "ERROR", MB_OK);
return NULL;
}
if(fread(&tgaheader, sizeof(TGAHeader), 1, file) == 0)
{
MessageBox(NULL, "Could not read file header", "ERROR", MB_OK);
if(file != NULL)
fclose(file);
return NULL;
}
if(memcmp(uTGAcompare, &tgaheader, sizeof(tgaheader)) == 0)
image = LoadUncompressedTGA(file);
else if(memcmp(cTGAcompare, &tgaheader, sizeof(tgaheader)) == 0)
image = LoadCompressedTGA(file);
else
{
MessageBox(NULL, "TGA file must be type 2 or type 10 ", "Invalid
Image", MB_OK); fclose(file); return NULL;
}
return image;
}
TextureImage* LoadUncompressedTGA(FILE * fTGA)
{
TGA tga;
TextureImage* image = new TextureImage;
if(fread(tga.header, sizeof(tga.header), 1, fTGA) == 0)
{
MessageBox(NULL, "Could not read info header", "ERROR", MB_OK);
if(fTGA != NULL)
{
fclose(fTGA);
}
return NULL;
}
image->sizeY = tga.header[1] * 256 + tga.header[0];
image->sizeX = tga.header[3] * 256 + tga.header[2];
image->bpp = tga.header[4];
tga.Width = image->sizeX;
tga.Height = image->sizeY;
tga.Bpp = image->bpp;
if((image->sizeX <= 0) || (image->sizeY <= 0) || ((image->bpp != 24) &&
(image->bpp !=32)))
{
MessageBox(NULL, "Invalid texture information", "ERROR", MB_OK);
if(fTGA != NULL)
{
fclose(fTGA);
}
return NULL;
}
if(image->bpp == 24)
{
image->type = GL_RGB;
}
else
{
image->type = GL_RGBA;
}
tga.bytesPerPixel = (tga.Bpp / 8);
tga.imageSize = (tga.bytesPerPixel * tga.Width * tga.Height);
image->data = (uint8_t *)malloc(tga.imageSize);
if(image->data == NULL)
{
MessageBox(NULL, "Could not allocate memory for image", "ERROR",
MB_OK); fclose(fTGA); return NULL;
}
if(fread(image->data, 1, tga.imageSize, fTGA) != tga.imageSize)
{
MessageBox(NULL, "Could not read image data", "ERROR", MB_OK);
if(image->data != NULL)
{
free(image->data);
}
fclose(fTGA);
return NULL;
}
for(uint32_t cswap = 0; cswap < (int)tga.imageSize; cswap +=
tga.bytesPerPixel)
{
image->data[cswap] ^= image->data[cswap+2] ^=
image->data[cswap] ^= image->data[cswap+2];
}
fclose(fTGA);
return image;
}
TextureImage* LoadCompressedTGA(FILE * fTGA)
{
TextureImage* image = new TextureImage;
TGA tga;
if(fread(tga.header, sizeof(tga.header), 1, fTGA) == 0)
{
MessageBox(NULL, "Could not read info header", "ERROR", MB_OK);
if(fTGA != NULL)
{
fclose(fTGA);
}
return NULL;
}
image->sizeX = tga.header[1] * 256 + tga.header[0];
image->sizeY = tga.header[3] * 256 + tga.header[2];
image->bpp = tga.header[4];
tga.Width = image->sizeX;
tga.Height = image->sizeY;
tga.Bpp = image->bpp;
if((image->sizeX <= 0) || (image->sizeY <= 0) || ((image->bpp != 24) &&
(image->bpp !=32)))
{
MessageBox(NULL, "Invalid texture information", "ERROR", MB_OK);
if(fTGA != NULL)
{
fclose(fTGA);
}
return NULL;
}
tga.bytesPerPixel = (tga.Bpp / 8);
tga.imageSize = (tga.bytesPerPixel * tga.Width * tga.Height);
image->data = (uint8_t *)malloc(tga.imageSize);
if(image->data == NULL)
{
MessageBox(NULL, "Could not allocate memory for image", "ERROR",
MB_OK); fclose(fTGA); return NULL;
}
uint32_t pixelcount = tga.Height * tga.Width;
uint32_t currentpixel = 0;
uint32_t currentbyte = 0;
uint8_t * colorbuffer = (uint8_t *)malloc(tga.bytesPerPixel);
do
{
uint8_t chunkheader = 0;
if(fread(&chunkheader, sizeof(uint8_t), 1, fTGA) == 0)
{
MessageBox(NULL, "Could not read RLE header", "ERROR",
MB_OK); if(fTGA != NULL)
{
fclose(fTGA);
}
if(image->data != NULL)
{
free(image->data);
}
return NULL;
}
if(chunkheader < 128)
{
chunkheader++;
for(short counter = 0; counter < chunkheader; counter++)
{
if(fread(colorbuffer, 1, tga.bytesPerPixel,
fTGA) != tga.bytesPerPixel)
{
MessageBox(NULL, "Could not read image
data", "ERROR", MB_OK);
if(fTGA != NULL)
{
fclose(fTGA);
}
if(colorbuffer != NULL)
{
free(colorbuffer);
}
if(image->data != NULL)
{
free(image->data);
}
return NULL;
}
image->data[currentbyte ] =
colorbuffer[2]; image->data[currentbyte + 1 ] = colorbuffer[1];
image->data[currentbyte + 2 ] =
colorbuffer[0];
if(tga.bytesPerPixel == 4)
{
image->data[currentbyte + 3] =
colorbuffer[3];
}
currentbyte += tga.bytesPerPixel;
currentpixel++;
if(currentpixel > pixelcount)
{
MessageBox(NULL, "Too many pixels read",
"ERROR", NULL);
if(fTGA != NULL)
{
fclose(fTGA);
}
if(colorbuffer != NULL)
{
free(colorbuffer);
}
if(image->data != NULL)
{
free(image->data);
}
return NULL;
}
}
}
else
{
chunkheader -= 127;
if(fread(colorbuffer, 1, tga.bytesPerPixel, fTGA) !=
tga.bytesPerPixel)
{
MessageBox(NULL, "Could not read from file",
"ERROR", MB_OK);
if(fTGA != NULL)
{
fclose(fTGA);
}
if(colorbuffer != NULL)
{
free(colorbuffer);
}
if(image->data != NULL)
{
free(image->data);
}
return NULL;
}
for(short counter = 0; counter < chunkheader; counter++)
{
image->data[currentbyte ] =
colorbuffer[2]; image->data[currentbyte + 1 ] = colorbuffer[1];
image->data[currentbyte + 2 ] =
colorbuffer[0];
if(tga.bytesPerPixel == 4)
{
image->data[currentbyte + 3] =
colorbuffer[3];
}
currentbyte += tga.bytesPerPixel;
currentpixel++;
if(currentpixel > pixelcount)
{
MessageBox(NULL, "Too many pixels read",
"ERROR", NULL);
if(fTGA != NULL)
{
fclose(fTGA);
}
if(colorbuffer != NULL)
{
free(colorbuffer);
}
if(image->data != NULL)
{
free(image->data);
}
return NULL;
}
}
}
}
while(currentpixel < pixelcount);
fclose(fTGA);
return image;
}
*/
} // End namespace OpenArena } // End namespace OpenArena

84
tga.h
View File

@@ -17,83 +17,25 @@
* Free Software Foundation, Inc., * * Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/ ***************************************************************************/
#ifndef OpenArena__tga_h__ #ifndef OpenArena__tga_h__
#define OpenArena__tga_h__ #define OpenArena__tga_h__
#if defined HAVE_CONFIG_H // clang-format off
#include "config.h" #include "config.h"
#endif #include <memory>
#include <cstdio>
#include <string> #include <string>
#include "image.h"
#include "texture.h" #include "texture.h"
// clang-format on
namespace OpenArena { namespace OpenArena {
/*!
* \brief class TargaImage : public ImageBase {
* Write brief comment for TGAHeader here. public:
* virtual ~TargaImage();
* Write detailed description for TGAHeader here. static std::shared_ptr<TargaImage> FromFile(std::string filename);
*
* \remarks
* Write remarks for TGAHeader here.
*
* \see
* Separate items with the '|' character.
*/
struct TGAHeader {
uint8_t Header[12]; // File Header To Determine File Type
}; };
} // End namespace OpenArena
/*! #endif // End !defined OpenArena__tga_h__
* \brief
* Write brief comment for TGA here.
*
* Write detailed description for TGA here.
*
* \remarks
* Write remarks for TGA here.
*
* \see
* Separate items with the '|' character.
*/
struct TGA {
uint8_t header[6]; // Holds The First 6 Useful Bytes Of The File
uint32_t bytesPerPixel; // Number Of BYTES Per Pixel (3 Or 4)
uint32_t imageSize; // Amount Of Memory Needed To Hold The Image
uint32_t type; // The Type Of Image, GL_RGB Or GL_RGBA
uint32_t Height; // Height Of Image
uint32_t Width; // Width Of Image
uint32_t Bpp; // Number Of BITS Per Pixel (24 Or 32)
};
/*!
* \brief
* Write brief comment for LoadTGA here.
*
* \param filename
* Description of parameter filename.
*
* \returns
* Write description of return value here.
*
* \throws <exception class>
* Description of criteria for throwing this exception.
*
* Write detailed description for LoadTGA here.
*
* \remarks
* Write remarks for LoadTGA here.
*
* \see
* Separate items with the '|' character.
*/
TextureImage* LoadTGA(const char* filename);
const uint8_t uTGAcompare[12] = {0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0}; // Uncompressed TGA Header
const uint8_t cTGAcompare[12] = {0, 0, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0}; // Compressed TGA Header
TextureImage* LoadUncompressedTGA(FILE*); // Load an Uncompressed file
TextureImage* LoadCompressedTGA(FILE*); // Load a Compressed file
}; // namespace OpenArena
#endif

View File

@@ -17,8 +17,12 @@
* Free Software Foundation, Inc., * * Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/ ***************************************************************************/
// clang-format off
#include "vector.h" #include "vector.h"
// clang-format on
namespace OpenArena { namespace OpenArena {
Vec3d::Vec3d(const Vec3d& orig) { Vec3d::Vec3d(const Vec3d& orig) {

960
vector.h

File diff suppressed because it is too large Load Diff

View File

@@ -17,5 +17,9 @@
* Free Software Foundation, Inc., * * Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/ ***************************************************************************/
#ifndef OpenArena__version_h__
#define OpenArena__version_h__
// #define OPENARENA_VERSION "OpenArena: v0.1.2" // #define OPENARENA_VERSION "OpenArena: v0.1.2"
#define OPENARENA_VERSION "OpenArena: git" #define OPENARENA_VERSION "OpenArena: git"
#endif // End !defined(OpenArena__version_h__)

View File

@@ -17,14 +17,18 @@
* Free Software Foundation, Inc., * * Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/ ***************************************************************************/
#include "window.h"
#include <OpenGL/gl.h> // clang-format off
#include <OpenGL/glu.h> #include "window.h"
#include <windows.h>
#include "opengl.h"
// clang-format on
namespace OpenArena { namespace OpenArena {
#pragma clang diagnostic push namespace {
#pragma clang diagnostic ignored "-Wdeprecated-declarations" using std::string;
} // End namespace
void OpenArena::Window::SwapBuffers() { void OpenArena::Window::SwapBuffers() {
#if defined USE_GLX #if defined USE_GLX
@@ -106,36 +110,16 @@ bool OpenArena::Window::Open() {
#endif #endif
attributes.override_redirect = true; attributes.override_redirect = true;
window = XCreateWindow(display, window = XCreateWindow(display, RootWindow(display, vi->screen), 0, 0, _width, _height, 0, vi->depth, InputOutput,
RootWindow(display, vi->screen), vi->visual, CWBorderPixel | CWColormap | CWEventMask | CWOverrideRedirect, &attributes);
0,
0,
_width,
_height,
0,
vi->depth,
InputOutput,
vi->visual,
CWBorderPixel | CWColormap | CWEventMask | CWOverrideRedirect,
&attributes);
XWarpPointer(display, None, window, 0, 0, 0, 0, 0, 0); XWarpPointer(display, None, window, 0, 0, 0, 0, 0, 0);
XMapRaised(display, window); XMapRaised(display, window);
XGrabKeyboard(display, window, true, GrabModeAsync, GrabModeAsync, CurrentTime); XGrabKeyboard(display, window, true, GrabModeAsync, GrabModeAsync, CurrentTime);
XGrabPointer(display, window, true, ButtonPressMask, GrabModeAsync, GrabModeAsync, window, None, CurrentTime); XGrabPointer(display, window, true, ButtonPressMask, GrabModeAsync, GrabModeAsync, window, None, CurrentTime);
XDefineCursor(display, window, CreateFullscreenCursor()); XDefineCursor(display, window, CreateFullscreenCursor());
} else { } else {
window = XCreateWindow(display, window = XCreateWindow(display, RootWindow(display, vi->screen), 0, 0, _width, _height, 0, vi->depth, InputOutput,
RootWindow(display, vi->screen), vi->visual, CWBorderPixel | CWColormap | CWEventMask, &attributes);
0,
0,
_width,
_height,
0,
vi->depth,
InputOutput,
vi->visual,
CWBorderPixel | CWColormap | CWEventMask,
&attributes);
wmDelete = XInternAtom(display, "WM_DELETE_WINDOW", true); wmDelete = XInternAtom(display, "WM_DELETE_WINDOW", true);
XSetWMProtocols(display, window, &wmDelete, 1); XSetWMProtocols(display, window, &wmDelete, 1);
XSetStandardProperties(display, window, GetName(), GetName(), None, NULL, 0, NULL); XSetStandardProperties(display, window, GetName(), GetName(), None, NULL, 0, NULL);
@@ -164,8 +148,7 @@ bool OpenArena::Window::Open() {
err = CreateNewWindow(kDocumentWindowClass, err = CreateNewWindow(kDocumentWindowClass,
kWindowStandardHandlerAttribute | kWindowCloseBoxAttribute | kWindowFullZoomAttribute kWindowStandardHandlerAttribute | kWindowCloseBoxAttribute | kWindowFullZoomAttribute
| kWindowCollapseBoxAttribute, | kWindowCollapseBoxAttribute,
&_bounds, &_bounds, &_window);
&_window);
if (err != noErr) { if (err != noErr) {
return false; return false;
} }
@@ -240,8 +223,7 @@ bool OpenArena::Window::Open() {
if (MessageBox(NULL, if (MessageBox(NULL,
"The Requested Fullscreen Mode Is Not Supported By\nYour " "The Requested Fullscreen Mode Is Not Supported By\nYour "
"Video Card. Use Windowed Mode Instead?", "Video Card. Use Windowed Mode Instead?",
"OpenArena", "OpenArena", MB_YESNO | MB_ICONEXCLAMATION)
MB_YESNO | MB_ICONEXCLAMATION)
== IDYES) == IDYES)
_fullscreen = false; _fullscreen = false;
else { else {
@@ -263,18 +245,9 @@ bool OpenArena::Window::Open() {
AdjustWindowRectEx(&WindowRect, dwStyle, false, dwExStyle); AdjustWindowRectEx(&WindowRect, dwStyle, false, dwExStyle);
if (!(window = CreateWindowEx(dwExStyle, if (!(window = CreateWindowEx(dwExStyle, "OpenArena v0.1.0", GetName(), WS_CLIPSIBLINGS | WS_CLIPCHILDREN | dwStyle,
"OpenArena v0.1.0", 0, 0, WindowRect.right - WindowRect.left, WindowRect.bottom - WindowRect.top, NULL,
GetName(), NULL, instance, NULL))) {
WS_CLIPSIBLINGS | WS_CLIPCHILDREN | dwStyle,
0,
0,
WindowRect.right - WindowRect.left,
WindowRect.bottom - WindowRect.top,
NULL,
NULL,
instance,
NULL))) {
Close(); Close();
MessageBox(NULL, "Window Creation Error.", "ERROR", MB_OK | MB_ICONEXCLAMATION); MessageBox(NULL, "Window Creation Error.", "ERROR", MB_OK | MB_ICONEXCLAMATION);
return false; return false;
@@ -284,7 +257,7 @@ bool OpenArena::Window::Open() {
1, 1,
PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER, PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER,
PFD_TYPE_RGBA, PFD_TYPE_RGBA,
_colorDepth, static_cast<BYTE>(_colorDepth),
0, 0,
0, 0,
0, 0,
@@ -526,5 +499,4 @@ Cursor OpenArena::Window::CreateFullscreenCursor() {
return cur; return cur;
} }
#endif #endif
#pragma clang diagnostic pop
} // End namespace OpenArena } // End namespace OpenArena

View File

@@ -17,42 +17,18 @@
* Free Software Foundation, Inc., * * Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/ ***************************************************************************/
#ifndef OpenArena__window_h__ #ifndef OpenArena__window_h__
#define OpenArena__window_h__ #define OpenArena__window_h__
#if defined HAVE_CONFIG_H // clang-format off
#include "config.h" #include "config.h"
#endif #include "opengl.h"
#include "screen.h" #include "screen.h"
#if defined USE_GLX
#include <GL/gl.h>
#include <GL/glu.h> //maybe not necessary
#include <GL/glx.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/keysym.h>
#if defined HAVE_XF86VIDMODE
#include <X11/extensions/xf86vmode.h>
#endif
#elif defined USE_AGL
#include <AGL/agl.h>
#include <OpenGL/gl.h>
#include <OpenGL/glu.h>
#elif defined USE_CGL
#include <OpenGL/OpenGL.h>
#include <OpenGL/gl.h>
#elif defined USE_WGL
#include <GL/gl.h>
#include <GL/glu.h>
#include <windows.h>
#endif
#ifdef WIN32
#endif
#include "vector.h" #include "vector.h"
// clang-format on
namespace OpenArena { namespace OpenArena {
class Window : public Screen { class Window : public Screen {
public: public:
@@ -68,43 +44,21 @@ class Window : public Screen {
public: public:
Window(); Window();
~Window(); virtual ~Window();
void Close(); virtual void Close();
bool Open(); virtual bool Open();
bool Open(string title, virtual bool Open(std::string title, int width, int height, int bits,
int width, bool fullscreenflag); // make that string a const char* after this works
int height, virtual void SetInitializer(Initializer* initializer);
int bits, virtual void SetResizer(Resizer* resizer);
bool fullscreenflag); // make that string a const char* after this works virtual void SwapBuffers();
void SetInitializer(Initializer* initializer); virtual void Resize(uint32_t width, uint32_t height);
void SetResizer(Resizer* resizer); virtual Vec2i GetMousePosition();
void SwapBuffers(); virtual void SetMousePosition(Vec2i pos);
void Resize(uint32_t width, uint32_t height);
Vec2i GetMousePosition();
void SetMousePosition(Vec2i pos);
#ifdef USE_GLX
Display* GetDisplay();
#endif
private: private:
#ifdef USE_GLX #ifdef USE_WGL
Cursor CreateWindowedCursor(); // TODO: move this to opengl/window
Cursor CreateFullscreenCursor();
int screen;
::Window window;
GLXContext hRC;
XSetWindowAttributes attributes;
bool doubleBuffered;
#if defined HAVE_XF86VIDMODE
XF86VidModeModeInfo vidMode;
#endif
int x, y;
Display* display;
#elif defined USE_AGL
AGLContext _aglContext;
WindowRef _window;
Rect _bounds;
#elif defined USE_WGL
HGLRC glContext; HGLRC glContext;
HWND window; HWND window;
HDC deviceContext; HDC deviceContext;
@@ -117,9 +71,10 @@ class Window : public Screen {
#if defined USE_GLX #if defined USE_GLX
static int attrListSgl[] = {GLX_RGBA, GLX_RED_SIZE, 4, GLX_GREEN_SIZE, 4, GLX_BLUE_SIZE, 4, GLX_DEPTH_SIZE, 16, None}; static int attrListSgl[] = {GLX_RGBA, GLX_RED_SIZE, 4, GLX_GREEN_SIZE, 4, GLX_BLUE_SIZE, 4, GLX_DEPTH_SIZE, 16, None};
static int attrListDbl[] = { static int attrListDbl[] = {GLX_RGBA, GLX_DOUBLEBUFFER, GLX_RED_SIZE, 4, GLX_GREEN_SIZE, 4, GLX_BLUE_SIZE,
GLX_RGBA, GLX_DOUBLEBUFFER, GLX_RED_SIZE, 4, GLX_GREEN_SIZE, 4, GLX_BLUE_SIZE, 4, GLX_DEPTH_SIZE, 16, None}; 4, GLX_DEPTH_SIZE, 16, None};
#elif defined USE_WGL #elif defined USE_WGL
// TODO: Move this to opengl/window.
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
#endif #endif

View File

@@ -17,46 +17,82 @@
* Free Software Foundation, Inc., * * Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/ ***************************************************************************/
#ifdef WIN32
// include necessary header files
#include <GL/glu.h>
#ifdef _WIN32
// clang-format off
// include necessary header files
#include "windows.h"
#include <iostream>
#include "DrawEvent.h"
#include "EventManager.h"
#include "KeyPressEvent.h"
#include "KeyReleaseEvent.h"
#include "Logger.h"
#include "WindowsLogger.h"
#include "console_logger.h"
#include "level.h"
#include "main.h" #include "main.h"
#include "mygl.h"
#include "opengl.h"
#include "opengl/window.h"
#include "vector.h" #include "vector.h"
#include "version.h" #include "version.h"
// clang-format on
namespace {
using OpenArena::ConsoleLogger;
using OpenArena::ControlScheme;
using OpenArena::DrawEvent;
using OpenArena::EventManager;
using OpenArena::g_Screen;
using OpenArena::KeyPressEvent;
using OpenArena::KeyReleaseEvent;
using OpenArena::Keys;
using OpenArena::Level;
using OpenArena::Logger;
using OpenArena::Vec2i; using OpenArena::Vec2i;
using OpenArena::WindowsLogger;
// link necessary libraries using OpenArena::OpenGL::Window;
#pragma comment(lib, "opengl32.lib") using std::exception;
#pragma comment(lib, "glu32.lib") using std::make_shared;
#pragma comment(lib, "glaux.lib") using std::string;
#pragma comment(lib, "winmm.lib") using std::to_string;
} // End namespace
// Ensure CDS_FULLSCREEN is defined
#ifndef CDS_FULLSCREEN
#define CDS_FULLSCREEN 4
#endif
using namespace std;
void InitControls(); void InitControls();
int InitGL(GLvoid); int InitGL(GLvoid);
void ReSizeGLScene(GLsizei width, GLsizei height); void ReSizeGLScene(GLsizei width, GLsizei height);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow); int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow);
LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam); LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
OpenArena::Keys TranslateKey(int keyCode); Keys TranslateKey(int keyCode);
void HandleConsoleKeyPress(OpenArena::Keys key); void HandleConsoleKeyPress(Keys key);
Level* level = nullptr;
bool keys[256] = {false};
bool keys2[256] = {false};
bool active = false;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Function Definitions // Function Definitions
int DrawGLScene(Level* level) {
level->Render();
g_Screen->SwapBuffers();
return 1;
}
// //
// void InitControls() // void InitControls()
// Purpose: // Purpose:
// Initializes controls by loading the default control config file "my.cfg". // Initializes controls by loading the default control config file "my.cfg".
void InitControls() { void InitControls() {
if (!level.LoadConfig("my.cfg")) level.LoadConfig(); if (!level->LoadConfig("my.cfg")) {
level->LoadConfig();
};
} }
// //
@@ -69,7 +105,7 @@ void InitControls() {
// //
int InitGL(GLvoid) { int InitGL(GLvoid) {
level.LoadGLTextures(); level->LoadGLTextures();
glEnable(GL_TEXTURE_2D); glEnable(GL_TEXTURE_2D);
glShadeModel(GL_SMOOTH); glShadeModel(GL_SMOOTH);
@@ -81,11 +117,11 @@ int InitGL(GLvoid) {
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
/*lighting disabled temporarily /*lighting disabled temporarily
glLightfv(GL_LIGHT1, GL_AMBIENT, level.LightAmbient); glLightfv(GL_LIGHT1, GL_AMBIENT, level->LightAmbient);
for(index=0; index<level.numLights; index++) for(index=0; index<level->numLights; index++)
{ {
glLightfv(GL_LIGHT1, GL_DIFFUSE, level.light[index].color); glLightfv(GL_LIGHT1, GL_DIFFUSE, level->light[index].color);
glLightfv(GL_LIGHT1, GL_POSITION, level.light[index].coords); glLightfv(GL_LIGHT1, GL_POSITION, level->light[index].coords);
} }
glEnable(GL_LIGHT1); glEnable(GL_LIGHT1);
@@ -140,8 +176,8 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
return 0; return 0;
} }
case WM_KEYDOWN: { case WM_KEYDOWN: {
if (level.showConsole) { if (level->showConsole) {
HandleConsoleKeyPress((OpenArena::Keys)TranslateKey(wParam)); HandleConsoleKeyPress((Keys)TranslateKey(wParam));
} else { } else {
keys[TranslateKey(wParam)] = true; keys[TranslateKey(wParam)] = true;
} }
@@ -191,331 +227,350 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
} }
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
auto p_console_logger = make_shared<ConsoleLogger>();
auto p_windows_logger = make_shared<WindowsLogger>();
p_windows_logger->SetMinType(Logger::MessageType::Error);
Logger::AddLogger(p_console_logger);
Logger::AddLogger(p_windows_logger);
Logger::LogDebug("Starting");
OpenArena::Logger::LogUnimplementedMethod;
MSG msg; MSG msg;
bool done = false; try {
g_Screen = new Window();
DrawEvent::DrawEventHandler* _drawEventHandler = new DrawEvent::DrawEventHandler(level);
KeyPressEvent::KeyPressEventHandler* _keyPressEventHandler = new KeyPressEvent::KeyPressEventHandler();
KeyReleaseEvent::KeyReleaseEventHandler* _keyReleaseEventHandler = new KeyReleaseEvent::KeyReleaseEventHandler();
if (strlen(lpCmdLine)) level.ParseCmds(lpCmdLine); EventManager* em = new EventManager();
level = new Level(em);
InitControls(); bool done = false;
if (strlen(lpCmdLine)) level->ParseCmds(lpCmdLine);
g_Screen.SetInitializer(new OpenArena::Window::Initializer()); InitControls();
g_Screen.SetResizer(new OpenArena::Window::Resizer()); g_Screen->SetInitializer(new Window::Initializer());
if (!g_Screen.Open(string(OPENARENA_VERSION), g_Screen->SetResizer(new Window::Resizer());
level.screen.GetWidth(), if (!g_Screen->Open(string(OPENARENA_VERSION), g_Screen->GetWidth(), g_Screen->GetHeight(),
level.screen.GetHeight(), g_Screen->GetColorDepth(), g_Screen->GetFullscreen())) {
level.screen.GetColorDepth(), Logger::LogError("Screen open failed.");
level.screen.GetFullscreen())) { return -1;
return 0;
}
level.SetWindow(&g_Screen);
level.glFont.SetScreenDimensions(level.screen.GetWidth() * 2, level.screen.GetHeight() * 2);
// level.glFont.BuildFont("oa\\textures\\menu\\font.bmp");//(level.gamedir + "\\textures\\menu\\font.bmp").c_str());
if (level.nextLevel == "") {
level.LoadMap("intro.map");
} else {
level.LoadMap();
}
while (!done) {
while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
if (msg.message == WM_QUIT) {
done = true;
} else {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
} }
if (active) { level->SetWindow(g_Screen);
if (keys[OpenArena::KEY_ESCAPE]) { level->glFont.SetScreenDimensions(g_Screen->GetWidth() * 2, g_Screen->GetHeight() * 2);
done = true;
} else {
level.defaultPlayer[0].camera.Update();
if (!level.showConsole) { if (level->nextLevel == "") {
if (level.mlook) { Logger::LogDebug("Loading intro.map");
using OpenArena::Vec2i; level->LoadMap("intro.map");
Vec2i middleOfScreen = Vec2i(g_Screen.GetWidth() / 2, g_Screen.GetHeight() / 2); } else {
Vec2i mousePosition = g_Screen.GetMousePosition(); Logger::LogDebug("Loading nextLevel: " + level->nextLevel);
if (mousePosition != middleOfScreen) { level->LoadMap();
// Vec2i mouseDelta = mousePosition - middleOfScreen; }
Vec2i mouseDelta = middleOfScreen - mousePosition; Logger::LogDebug("About to start main loop.");
g_Screen.SetMousePosition(middleOfScreen); while (!done) {
const float MOUSE_SENSITIVITY_HORIZONTAL = 0.005f; // Logger::LogDebug("in while(!done)");
const float MOUSE_SENSITIVITY_VERTICAL = 0.005f; while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
float horizontalAngle = mouseDelta.x * MOUSE_SENSITIVITY_HORIZONTAL; if (msg.message == WM_QUIT) {
float verticalAngle = mouseDelta.y * MOUSE_SENSITIVITY_VERTICAL; done = true;
level.defaultPlayer[0].camera.RotateHorizontal(horizontalAngle); } else {
level.defaultPlayer[0].camera.RotateVertical(verticalAngle); TranslateMessage(&msg);
} DispatchMessage(&msg);
} else { }
g_Screen.SetMousePosition(Vec2i(g_Screen.GetWidth() / 2, g_Screen.GetHeight() / 2)); }
// SetCursorPos(g_Screen.GetWidth()/2, g_Screen.GetHeight()/2);
} if (active) {
if (keys[OpenArena::KEY_ESCAPE]) {
////////// done = true;
// Move Backward } else {
if (!level.defaultPlayer->controls.backward.IsEmpty()) { level->defaultPlayer[0].camera.Update();
level.defaultPlayer->controls.backward.FirstPosition();
if (keys[level.defaultPlayer->controls.backward.Retrieve()]) { if (!level->showConsole) {
level.defaultPlayer->camera.MoveCamera(-level.moveSpeed); if (level->mlook) {
} else { Vec2i middleOfScreen = Vec2i(g_Screen->GetWidth() / 2, g_Screen->GetHeight() / 2);
while (level.defaultPlayer->controls.backward.NextPosition() Vec2i mousePosition = g_Screen->GetMousePosition();
&& (keys[level.defaultPlayer->controls.backward.Retrieve()] != true)) if (mousePosition != middleOfScreen) {
; // Vec2i mouseDelta = mousePosition - middleOfScreen;
{ Vec2i mouseDelta = middleOfScreen - mousePosition;
if (keys[level.defaultPlayer->controls.backward.Retrieve()]) { g_Screen->SetMousePosition(middleOfScreen);
level.defaultPlayer->camera.MoveCamera(-level.moveSpeed); const float MOUSE_SENSITIVITY_HORIZONTAL = 0.005f;
} const float MOUSE_SENSITIVITY_VERTICAL = 0.005f;
} float horizontalAngle = mouseDelta.x * MOUSE_SENSITIVITY_HORIZONTAL;
} float verticalAngle = mouseDelta.y * MOUSE_SENSITIVITY_VERTICAL;
} level->defaultPlayer[0].camera.RotateHorizontal(horizontalAngle);
level->defaultPlayer[0].camera.RotateVertical(verticalAngle);
////////// }
// Move forward } else {
if (!level.defaultPlayer->controls.forward.IsEmpty()) { g_Screen->SetMousePosition(Vec2i(g_Screen->GetWidth() / 2, g_Screen->GetHeight() / 2));
level.defaultPlayer->controls.forward.FirstPosition(); }
if (keys[level.defaultPlayer->controls.forward.Retrieve()]) {
level.defaultPlayer->camera.MoveCamera(level.moveSpeed); // //////////
} else { // // Move Backward
while (level.defaultPlayer->controls.forward.NextPosition() // if (!level->defaultPlayer->controls.backward.IsEmpty()) {
&& (keys[level.defaultPlayer->controls.forward.Retrieve()] != true)) // level->defaultPlayer->controls.backward.FirstPosition();
; // if (keys[level->defaultPlayer->controls.backward.Retrieve()]) {
{ // level->defaultPlayer->camera.MoveCamera(-level->moveSpeed);
if (keys[level.defaultPlayer->controls.forward.Retrieve()]) { // } else {
level.defaultPlayer->camera.MoveCamera(level.moveSpeed); // while (level->defaultPlayer->controls.backward.NextPosition()
} // && (keys[level->defaultPlayer->controls.backward.Retrieve()] != true))
} // ;
} // {
} // if (keys[level->defaultPlayer->controls.backward.Retrieve()]) {
// level->defaultPlayer->camera.MoveCamera(-level->moveSpeed);
////////// // }
// Strafe Left // }
if (!level.defaultPlayer->controls.moveLeft.IsEmpty()) { // }
level.defaultPlayer->controls.moveLeft.FirstPosition(); // }
if (keys[level.defaultPlayer->controls.moveLeft.Retrieve()]) {
level.defaultPlayer->camera.StrafeCamera(-level.moveSpeed); // //////////
} else { // // Move forward
while (level.defaultPlayer->controls.moveLeft.NextPosition() // if (!level->defaultPlayer->controls.forward.IsEmpty()) {
&& (keys[level.defaultPlayer->controls.moveLeft.Retrieve()] != true)) // level->defaultPlayer->controls.forward.FirstPosition();
; // if (keys[level->defaultPlayer->controls.forward.Retrieve()]) {
{ // level->defaultPlayer->camera.MoveCamera(level->moveSpeed);
if (keys[level.defaultPlayer->controls.moveLeft.Retrieve()]) { // } else {
level.defaultPlayer->camera.StrafeCamera(-level.moveSpeed); // while (level->defaultPlayer->controls.forward.NextPosition()
} // && (keys[level->defaultPlayer->controls.forward.Retrieve()] != true))
} // ;
} // {
} // if (keys[level->defaultPlayer->controls.forward.Retrieve()]) {
// level->defaultPlayer->camera.MoveCamera(level->moveSpeed);
////////// // }
// Strafe Right // }
if (!level.defaultPlayer->controls.moveRight.IsEmpty()) { // }
level.defaultPlayer->controls.moveRight.FirstPosition(); // }
if (keys[level.defaultPlayer->controls.moveRight.Retrieve()]) {
level.defaultPlayer[0].camera.StrafeCamera(level.moveSpeed); // //////////
} else { // // Strafe Left
while (level.defaultPlayer->controls.moveRight.NextPosition() // if (!level->defaultPlayer->controls.moveLeft.IsEmpty()) {
&& (keys[level.defaultPlayer->controls.moveRight.Retrieve()] != true)) // level->defaultPlayer->controls.moveLeft.FirstPosition();
; // if (keys[level->defaultPlayer->controls.moveLeft.Retrieve()]) {
{ // level->defaultPlayer->camera.StrafeCamera(-level->moveSpeed);
if (keys[level.defaultPlayer->controls.moveRight.Retrieve()]) { // } else {
level.defaultPlayer->camera.StrafeCamera(level.moveSpeed); // while (level->defaultPlayer->controls.moveLeft.NextPosition()
} // && (keys[level->defaultPlayer->controls.moveLeft.Retrieve()] != true))
} // ;
} // {
} // if (keys[level->defaultPlayer->controls.moveLeft.Retrieve()]) {
// level->defaultPlayer->camera.StrafeCamera(-level->moveSpeed);
////////// // }
// Keyboard Look Left // }
if (!level.defaultPlayer->controls.lookLeft.IsEmpty()) { // }
level.defaultPlayer->controls.lookLeft.FirstPosition(); // }
if (keys[level.defaultPlayer->controls.lookLeft.Retrieve()]) {
level.defaultPlayer[0].camera.RotateView(level.turnSpeed, 0, 1, 0); // //////////
} else { // // Strafe Right
while (level.defaultPlayer->controls.lookLeft.NextPosition() // if (!level->defaultPlayer->controls.moveRight.IsEmpty()) {
&& (keys[level.defaultPlayer->controls.lookLeft.Retrieve()] != true)) // level->defaultPlayer->controls.moveRight.FirstPosition();
; // if (keys[level->defaultPlayer->controls.moveRight.Retrieve()]) {
{ // level->defaultPlayer[0].camera.StrafeCamera(level->moveSpeed);
if (keys[level.defaultPlayer->controls.lookLeft.Retrieve()]) { // } else {
level.defaultPlayer[0].camera.RotateView(level.turnSpeed, 0, 1, 0); // while (level->defaultPlayer->controls.moveRight.NextPosition()
} // && (keys[level->defaultPlayer->controls.moveRight.Retrieve()] != true))
} // ;
} // {
} // if (keys[level->defaultPlayer->controls.moveRight.Retrieve()]) {
// level->defaultPlayer->camera.StrafeCamera(level->moveSpeed);
////////// // }
// Keyboard Look Right // }
if (!level.defaultPlayer->controls.lookRight.IsEmpty()) { // }
level.defaultPlayer->controls.lookRight.FirstPosition(); // }
if (keys[level.defaultPlayer->controls.lookRight.Retrieve()]) {
level.defaultPlayer->camera.RotateView(-level.turnSpeed, 0, 1, 0); // //////////
} else { // // Keyboard Look Left
while (level.defaultPlayer->controls.lookRight.NextPosition() // if (!level->defaultPlayer->controls.lookLeft.IsEmpty()) {
&& (keys[level.defaultPlayer->controls.lookRight.Retrieve()] != true)) // level->defaultPlayer->controls.lookLeft.FirstPosition();
; // if (keys[level->defaultPlayer->controls.lookLeft.Retrieve()]) {
{ // level->defaultPlayer[0].camera.RotateView(level->turnSpeed, 0, 1, 0);
if (keys[level.defaultPlayer->controls.lookRight.Retrieve()]) { // } else {
level.defaultPlayer->camera.RotateView(-level.turnSpeed, 0, 1, 0); // while (level->defaultPlayer->controls.lookLeft.NextPosition()
} // && (keys[level->defaultPlayer->controls.lookLeft.Retrieve()] != true))
} // ;
} // {
} // if (keys[level->defaultPlayer->controls.lookLeft.Retrieve()]) {
// level->defaultPlayer[0].camera.RotateView(level->turnSpeed, 0, 1, 0);
////////// // }
// Keyboard Look Up // }
if (!level.defaultPlayer->controls.lookUp.IsEmpty()) { // }
level.defaultPlayer->controls.lookUp.FirstPosition(); // }
if (keys[level.defaultPlayer->controls.lookUp.Retrieve()]) {
level.defaultPlayer->camera.RotateView(level.turnSpeed, 1, 0, 0); // //////////
} else { // // Keyboard Look Right
while (level.defaultPlayer->controls.lookUp.NextPosition() // if (!level->defaultPlayer->controls.lookRight.IsEmpty()) {
&& (keys[level.defaultPlayer->controls.lookUp.Retrieve()] != true)) // level->defaultPlayer->controls.lookRight.FirstPosition();
; // if (keys[level->defaultPlayer->controls.lookRight.Retrieve()]) {
{ // level->defaultPlayer->camera.RotateView(-level->turnSpeed, 0, 1, 0);
if (keys[level.defaultPlayer->controls.lookUp.Retrieve()]) { // } else {
level.defaultPlayer->camera.RotateView(level.turnSpeed, 1, 0, 0); // while (level->defaultPlayer->controls.lookRight.NextPosition()
} // && (keys[level->defaultPlayer->controls.lookRight.Retrieve()] != true))
} // ;
} // {
} // if (keys[level->defaultPlayer->controls.lookRight.Retrieve()]) {
// level->defaultPlayer->camera.RotateView(-level->turnSpeed, 0, 1, 0);
////////// // }
// Keyboard Look Down // }
if (!level.defaultPlayer->controls.lookDown.IsEmpty()) { // }
level.defaultPlayer->controls.lookDown.FirstPosition(); // }
if (keys[level.defaultPlayer->controls.lookDown.Retrieve()]) {
level.defaultPlayer->camera.RotateView(-level.turnSpeed, 1, 0, 0); // //////////
} else { // // Keyboard Look Up
while (level.defaultPlayer->controls.lookDown.NextPosition() // if (!level->defaultPlayer->controls.lookUp.IsEmpty()) {
&& (keys[level.defaultPlayer->controls.lookDown.Retrieve()] != true)) // level->defaultPlayer->controls.lookUp.FirstPosition();
; // if (keys[level->defaultPlayer->controls.lookUp.Retrieve()]) {
{ // level->defaultPlayer->camera.RotateView(level->turnSpeed, 1, 0, 0);
if (keys[level.defaultPlayer->controls.lookDown.Retrieve()]) { // } else {
level.defaultPlayer->camera.RotateView(-level.turnSpeed, 1, 0, 0); // while (level->defaultPlayer->controls.lookUp.NextPosition()
} // && (keys[level->defaultPlayer->controls.lookUp.Retrieve()] != true))
} // ;
} // {
} // if (keys[level->defaultPlayer->controls.lookUp.Retrieve()]) {
// level->defaultPlayer->camera.RotateView(level->turnSpeed, 1, 0, 0);
////////// // }
// Toggle Show FPS // }
if (!level.defaultPlayer->controls.toggleFPS.IsEmpty()) { // }
level.defaultPlayer->controls.toggleFPS.FirstPosition(); // }
if (keys[level.defaultPlayer->controls.toggleFPS.Retrieve()]) {
if (!keys2[level.defaultPlayer->controls.toggleFPS.Retrieve()]) { // //////////
level.showFPS = !level.showFPS; // // Keyboard Look Down
} // if (!level->defaultPlayer->controls.lookDown.IsEmpty()) {
} else { // level->defaultPlayer->controls.lookDown.FirstPosition();
while (level.defaultPlayer->controls.toggleFPS.NextPosition() // if (keys[level->defaultPlayer->controls.lookDown.Retrieve()]) {
&& (keys[level.defaultPlayer->controls.toggleFPS.Retrieve()] != true)) // level->defaultPlayer->camera.RotateView(-level->turnSpeed, 1, 0, 0);
; // } else {
{ // while (level->defaultPlayer->controls.lookDown.NextPosition()
if (keys[level.defaultPlayer->controls.toggleFPS.Retrieve()]) { // && (keys[level->defaultPlayer->controls.lookDown.Retrieve()] != true))
if (!keys2[level.defaultPlayer->controls.toggleFPS.Retrieve()]) { // ;
level.showFPS = !level.showFPS; // {
} // if (keys[level->defaultPlayer->controls.lookDown.Retrieve()]) {
} // level->defaultPlayer->camera.RotateView(-level->turnSpeed, 1, 0, 0);
} // }
} // }
} // }
// }
//////////
// Toggle MouseLook // //////////
if (!level.defaultPlayer->controls.toggleMouseLook.IsEmpty()) { // // Toggle Show FPS
level.defaultPlayer->controls.toggleMouseLook.FirstPosition(); // if (!level->defaultPlayer->controls.toggleFPS.IsEmpty()) {
if (keys[level.defaultPlayer->controls.toggleMouseLook.Retrieve()]) { // level->defaultPlayer->controls.toggleFPS.FirstPosition();
if (keys2[level.defaultPlayer->controls.toggleMouseLook.Retrieve()]) { // if (keys[level->defaultPlayer->controls.toggleFPS.Retrieve()]) {
level.mlook = !level.mlook; // if (!keys2[level->defaultPlayer->controls.toggleFPS.Retrieve()]) {
} // level->showFPS = !level->showFPS;
} else { // }
while (level.defaultPlayer->controls.toggleMouseLook.NextPosition() // } else {
&& (keys[level.defaultPlayer->controls.toggleMouseLook.Retrieve()] != true)) // while (level->defaultPlayer->controls.toggleFPS.NextPosition()
; // && (keys[level->defaultPlayer->controls.toggleFPS.Retrieve()] != true))
{ // ;
if (keys[level.defaultPlayer->controls.toggleMouseLook.Retrieve()]) { // {
if (keys2[level.defaultPlayer->controls.toggleMouseLook.Retrieve()]) { // if (keys[level->defaultPlayer->controls.toggleFPS.Retrieve()]) {
level.mlook = !level.mlook; // if (!keys2[level->defaultPlayer->controls.toggleFPS.Retrieve()]) {
} // level->showFPS = !level->showFPS;
} // }
} // }
} // }
} // }
// }
//////////
// Toggle Console // //////////
if (!level.defaultPlayer[0].controls.toggleConsole.IsEmpty()) { // // Toggle MouseLook
level.defaultPlayer[0].controls.toggleConsole.FirstPosition(); // if (!level->defaultPlayer->controls.toggleMouseLook.IsEmpty()) {
if (keys[level.defaultPlayer[0].controls.toggleConsole.Retrieve()]) { // level->defaultPlayer->controls.toggleMouseLook.FirstPosition();
if (!keys2[level.defaultPlayer[0].controls.toggleConsole.Retrieve()]) { // if (keys[level->defaultPlayer->controls.toggleMouseLook.Retrieve()]) {
level.showConsole = !level.showConsole; // if (keys2[level->defaultPlayer->controls.toggleMouseLook.Retrieve()]) {
keys2[level.defaultPlayer[0].controls.toggleConsole.Retrieve()] = true; // level->mlook = !level->mlook;
} // }
} else { // } else {
while (level.defaultPlayer[0].controls.toggleConsole.NextPosition() // while (level->defaultPlayer->controls.toggleMouseLook.NextPosition()
&& (keys[level.defaultPlayer[0].controls.toggleConsole.Retrieve()] != true)) // && (keys[level->defaultPlayer->controls.toggleMouseLook.Retrieve()] != true))
; // ;
{ // {
if (keys[level.defaultPlayer[0].controls.toggleConsole.Retrieve()]) { // if (keys[level->defaultPlayer->controls.toggleMouseLook.Retrieve()]) {
if (!keys2[level.defaultPlayer[0].controls.toggleConsole.Retrieve()]) { // if (keys2[level->defaultPlayer->controls.toggleMouseLook.Retrieve()]) {
level.showConsole = !level.showConsole; // level->mlook = !level->mlook;
keys2[level.defaultPlayer[0].controls.toggleConsole.Retrieve()] = true; // }
} // }
} // }
} // }
} // }
}
// //////////
////////// // // Toggle Console
// Quick MouseLook // if (!level->defaultPlayer[0].controls.toggleConsole.IsEmpty()) {
if (!level.defaultPlayer->controls.quickMouseLook.IsEmpty()) { // level->defaultPlayer[0].controls.toggleConsole.FirstPosition();
level.defaultPlayer->controls.quickMouseLook.FirstPosition(); // if (keys[level->defaultPlayer[0].controls.toggleConsole.Retrieve()]) {
if (keys[level.defaultPlayer->controls.quickMouseLook.Retrieve()]) { // if (!keys2[level->defaultPlayer[0].controls.toggleConsole.Retrieve()]) {
if (keys2[level.defaultPlayer->controls.quickMouseLook.Retrieve()]) { // level->showConsole = !level->showConsole;
level.mlook = !level.mlook; // keys2[level->defaultPlayer[0].controls.toggleConsole.Retrieve()] = true;
} // }
} else { // } else {
while (level.defaultPlayer->controls.quickMouseLook.NextPosition() // while (level->defaultPlayer[0].controls.toggleConsole.NextPosition()
&& (keys[level.defaultPlayer->controls.quickMouseLook.Retrieve()] != true)) // && (keys[level->defaultPlayer[0].controls.toggleConsole.Retrieve()] != true))
; // ;
{ // {
if (keys[level.defaultPlayer->controls.quickMouseLook.Retrieve()]) { // if (keys[level->defaultPlayer[0].controls.toggleConsole.Retrieve()]) {
if (keys2[level.defaultPlayer->controls.quickMouseLook.Retrieve()]) { // if (!keys2[level->defaultPlayer[0].controls.toggleConsole.Retrieve()]) {
level.mlook = !level.mlook; // level->showConsole = !level->showConsole;
} // keys2[level->defaultPlayer[0].controls.toggleConsole.Retrieve()] = true;
} // }
} // }
} // }
} // }
// level.Render(); // }
// //////////
// // Quick MouseLook
// if (!level->defaultPlayer->controls.quickMouseLook.IsEmpty()) {
// level->defaultPlayer->controls.quickMouseLook.FirstPosition();
// if (keys[level->defaultPlayer->controls.quickMouseLook.Retrieve()]) {
// if (keys2[level->defaultPlayer->controls.quickMouseLook.Retrieve()]) {
// level->mlook = !level->mlook;
// }
// } else {
// while (level->defaultPlayer->controls.quickMouseLook.NextPosition()
// && (keys[level->defaultPlayer->controls.quickMouseLook.Retrieve()] != true))
// ;
// {
// if (keys[level->defaultPlayer->controls.quickMouseLook.Retrieve()]) {
// if (keys2[level->defaultPlayer->controls.quickMouseLook.Retrieve()]) {
// level->mlook = !level->mlook;
// }
// }
// }
// }
// }
// level->Render();
}
level->Render();
//
}
}
// Why the hell are we swapping buffers even if the window is not active?
g_Screen->SwapBuffers();
if (keys[Keys::KEY_F1]) {
keys[Keys::KEY_F1] = false;
g_Screen->Close();
g_Screen->ToggleFullscreen();
if (!g_Screen->Open("OpenArena", g_Screen->GetWidth(), g_Screen->GetHeight(), g_Screen->GetColorDepth(),
g_Screen->GetFullscreen())) {
Logger::LogError("Window failed to reopen after changing fullscreen flag.");
return -1;
} }
level.Render();
//
} }
} }
g_Screen.SwapBuffers(); } catch (const exception& ex) {
Logger::LogWtf("Unhandled exception", ex);
if (keys[OpenArena::KEY_F1]) { } catch (...) {
keys[OpenArena::KEY_F1] = false; Logger::LogWtf("Unhandled exception");
g_Screen.Close();
g_Screen.ToggleFullscreen();
if (!g_Screen.Open("OpenArena",
g_Screen.GetWidth(),
g_Screen.GetHeight(),
g_Screen.GetColorDepth(),
g_Screen.GetFullscreen())) {
return 0;
}
}
} }
level.UnloadMap(); Logger::LogDebug("level->UnloadMap()");
g_Screen.Close(); level->UnloadMap();
g_Screen->Close();
Logger::LogDebug("g_Screen->Close()");
Logger::LogDebug("Exiting with msg.wParam " + to_string(msg.wParam));
return (msg.wParam); return (msg.wParam);
} }
OpenArena::Keys TranslateKey(int keyCode) { Keys TranslateKey(int keyCode) {
switch (keyCode) { switch (keyCode) {
case VK_LEFT: case VK_LEFT:
return OpenArena::KEY_LEFT; return OpenArena::KEY_LEFT;
@@ -724,36 +779,30 @@ OpenArena::Keys TranslateKey(int keyCode) {
} }
} }
void HandleConsoleKeyPress(OpenArena::Keys key) { void HandleConsoleKeyPress(Keys key) {
// See if we need to hide the console // See if we need to hide the console
level.defaultPlayer[0].controls.toggleConsole.FirstPosition(); if (level->defaultPlayer->controls.GetAction(key) == ControlScheme::ACTION_TOGGLE_CONSOLE) {
if (key == level.defaultPlayer[0].controls.toggleConsole.Retrieve()) { level->showConsole = false;
level.showConsole = false;
} else {
while (level.defaultPlayer[0].controls.toggleConsole.NextPosition() && level.showConsole) {
if (level.defaultPlayer[0].controls.toggleConsole.Retrieve() == key) {
level.showConsole = false;
}
}
} }
switch (key) { switch (key) {
case OpenArena::KEY_SHIFT: case OpenArena::KEY_SHIFT:
keys[OpenArena::KEY_SHIFT] = true; keys[OpenArena::KEY_SHIFT] = true;
break; break;
case OpenArena::KEY_RETURN: case OpenArena::KEY_RETURN:
level.UpdateConsole('\n'); level->UpdateConsole('\n');
break; break;
case OpenArena::KEY_SPACE: case OpenArena::KEY_SPACE:
printf("hello"); printf("hello");
level.UpdateConsole(' '); level->UpdateConsole(' ');
break; break;
case OpenArena::KEY_BACK: case OpenArena::KEY_BACK:
level.UpdateConsole(OpenArena::KEY_BACK); level->UpdateConsole(OpenArena::KEY_BACK);
break; break;
default: default:
char ascii = OpenArena::KeyToASCII(key, keys[OpenArena::KEY_SHIFT]); char ascii = KeyToASCII(key, keys[OpenArena::KEY_SHIFT]);
if (ascii != '\0') { if (ascii != '\0') {
level.UpdateConsole(ascii); level->UpdateConsole(ascii);
} }
} }
} }

View File

@@ -17,15 +17,15 @@
* Free Software Foundation, Inc., * * Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/ ***************************************************************************/
#ifndef OpenArena__world_defs_h__
#define OpenArena__world_defs_h__
#if defined HAVE_CONFIG_H #ifndef OpenArena__worlddefs_h__
#define OpenArena__worlddefs_h__
// clang-format off
#include "config.h" #include "config.h"
#endif
#include "level.h" #include "level.h"
// clang-format on
// static OpenArena::Level level; // static OpenArena::Level level;
#endif // End !defined(OpenArena__world_defs_h__) #endif // End !defined(OpenArena__worlddefs_h__)

View File

@@ -17,11 +17,15 @@
* Free Software Foundation, Inc., * * Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/ ***************************************************************************/
// clang-format off
#include "x11.h" #include "x11.h"
#if defined USE_GLX #if defined USE_GLX
#include "main.h" #include "main.h"
#include "version.h" #include "version.h"
#endif
// clang-format on
#if defined USE_GLX
int InitGL(OpenArena::Level* level) { int InitGL(OpenArena::Level* level) {
level->LoadGLTextures(); level->LoadGLTextures();

8
x11.h
View File

@@ -17,17 +17,19 @@
* Free Software Foundation, Inc., * * Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/ ***************************************************************************/
#ifndef OpenArena__x11_h__ #ifndef OpenArena__x11_h__
#define OpenArena__x11_h__ #define OpenArena__x11_h__
#if defined HAVE_CONFIG_H // clang-format off
#include "config.h" #include "config.h"
#endif
#if defined USE_GLX #if defined USE_GLX
#include "EventManager.h" #include "EventManager.h"
#include "level.h" #include "level.h"
#include "mygl.h" #include "mygl.h"
#endif
// clang-format on
#if defined USE_GLX
int DrawGLScene(); int DrawGLScene();
OpenArena::Keys TranslateButton(int keyCode); OpenArena::Keys TranslateButton(int keyCode);
OpenArena::Keys TranslateKey(int keyCode); OpenArena::Keys TranslateKey(int keyCode);