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-*
/.vscode

321
BUILD
View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -17,18 +17,22 @@
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
// clang-format off
#include "EventManager.h"
#include <cstdlib>
#include <iostream>
// clang-format on
namespace OpenArena {
EventManager::EventManager() {}
void EventManager::SendEvent(Event* event) {
unsigned int index;
for (index = 0; index < eventHandlers.Length(); index++) {
for (index = 0; index < eventHandlers.size(); index++) {
Event::EventHandler* handler = eventHandlers[index];
if (handler->Handles(event->GetEventType())) {
handler->HandleEvent(event);
@@ -55,6 +59,6 @@ void EventManager::SendEvent(Event event)
*/
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., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#ifndef OpenArena__EventManager_h__
#define OpenArena__EventManager_h__
// clang-format off
#include "config.h"
#include "Event.h"
#include "list.h"
#include <vector>
// clang-format on
namespace OpenArena {
class EventManager {
@@ -31,7 +35,7 @@ class EventManager {
void RegisterEventHandler(Event::EventHandler* eventHandler);
private:
list<Event::EventHandler*> eventHandlers;
std::vector<Event::EventHandler*> eventHandlers;
};
} // End namespace OpenArena
#endif // End OpenArena__EventManager_h__
#endif // End !defined(OpenArena__EventManager_h__)

View File

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

View File

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

View File

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

View File

@@ -17,11 +17,16 @@
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#ifndef OpenArena__KeyReleaseEvent_h__
#define OpenArena__KeyReleaseEvent_h__
// clang-format off
#include "config.h"
#include "Event.h"
#include "keys.h"
// clang-format on
namespace OpenArena {
class KeyReleaseEvent : public Event {
public:
@@ -43,4 +48,4 @@ class KeyReleaseEvent : public Event {
};
}; // 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., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#ifndef OpenArena__Logger_h__
#define OpenArena__Logger_h__
// clang-format off
#include <exception>
#include <memory>
#include <string>
#if defined HAVE_CONFIG_H
#include "config.h"
#endif
// clang-format on
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 {
public:
/*!
* \brief
* Write brief comment for MESSAGETYPE_DEBUG here.
*/
enum MessageType { MESSAGETYPE_ALL, MESSAGETYPE_NONE, MESSAGETYPE_INFORMATION, MESSAGETYPE_ERROR, MESSAGETYPE_DEBUG };
enum MessageType { Unknown = 0, Debug, Verbose, Info, Warning, Error, Wtf };
/*!
* \brief
* 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) {}
Logger();
virtual ~Logger();
/*!
* \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) = 0;
/*!
* \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) = 0;
virtual void LogMessage(const MessageType& type, const std::string& message) const = 0;
virtual void LogError(const MessageType& type, const std::exception& ex) const = 0;
virtual void LogError(const MessageType& type, const std::string& message, const std::exception& ex) const = 0;
virtual void SetMinType(const MessageType& type);
virtual void SetMaxType(const MessageType& type);
virtual MessageType GetMinType() const;
virtual MessageType GetMaxType() const;
// This one is special and annoying because it requires macros until the minimum standard is c++20.
#if __cplusplus >= 202002L
static void LogUnimplementedMethod(std::source_location = std::source_location::current());
#else
static void LogUnimplementedMethodReal(std::string method_name);
#endif
static void LogUnhandledError(const std::exception& ex);
static void LogUnimplementedFeature(const std::string& feature);
static void LogWtf(const std::string& message);
static void LogWtf(const std::exception& ex);
static void LogWtf(const std::string& message, const std::exception& ex);
static void LogError(const std::string& message);
static void LogError(const std::exception& ex);
static void LogError(const std::string& message, const std::exception& ex);
static void LogWarning(const std::string& message);
static void LogWarning(const std::exception& ex);
static void LogWarning(const std::string& message, const std::exception& ex);
static void LogInfo(const std::string& message);
static void LogInfo(const std::exception& ex);
static void LogInfo(const std::string& message, const std::exception& ex);
static void LogDebug(const std::string& message);
static void LogDebug(const std::exception& ex);
static void LogDebug(const std::string& message, const std::exception& ex);
static void LogVerbose(const std::string& message);
static void LogVerbose(const std::exception& ex);
static void LogVerbose(const std::string& message, const std::exception& ex);
static void Log(const MessageType& type, const std::string& message);
static void Log(const MessageType& type, const std::exception& ex);
static void Log(const MessageType& type, const std::string& message, const std::exception& ex);
static void LogToDo(const std::string& message);
static void Reset();
static void AddLogger(std::shared_ptr<Logger> logger);
private:
MessageType min_type_;
MessageType max_type_;
};
} // 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__)

View File

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

View File

@@ -17,12 +17,14 @@
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#ifndef OpenArena__Model_h__
#define OpenArena__Model_h__
#if defined HAVE_CONFIG_H
// clang-format off
#include "config.h"
#endif
// clang-format on
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., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
// clang-format off
#include "Object.h"
// clang-format on
namespace OpenArena {
namespace {
const char kClassName_OpenArena_Object[] = "Object";
}
Object::Object() {}
Object::~Object() {}
const char* Object::GetClassName() {
return 0x0;
return kClassName_OpenArena_Object;
}
} // End namespace OpenArena

View File

@@ -17,6 +17,7 @@
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#ifndef OpenArena__Object_h__
#define OpenArena__Object_h__
@@ -29,4 +30,4 @@ class Object {
};
}; // 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., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
// clang-format off
#include "Point.h"
// clang-format on

View File

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

View File

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

View File

@@ -17,11 +17,12 @@
* Free Software Foundation, Inc., *
* 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 {
class Rectangle {};
}; // 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(
name = "bazel_skylib",
sha256 = "f7be3474d42aae265405a592bb7da8e171919d74c16f082a5457840f06054728",
urls = ["https://github.com/bazelbuild/bazel-skylib/releases/download/1.2.1/bazel-skylib-1.2.1.tar.gz"],
name = "TinyTest",
sha256 = "d6729abbec6ac167635be7463d8c37ca54b08e506e61553236b50c5ad30e8736",
strip_prefix = "TinyTest-a4109d2f494fd3fd3cc47069239fd3c79f728d5a",
urls = ["https://github.com/headhunter45/TinyTest/archive/a4109d2f494fd3fd3cc47069239fd3c79f728d5a.zip"],
)
http_archive(
name = "build_bazel_rules_apple",
sha256 = "9e26307516c4d5f2ad4aee90ac01eb8cd31f9b8d6ea93619fc64b3cbc81b0944",
url = "https://github.com/bazelbuild/rules_apple/releases/download/2.2.0/rules_apple.2.2.0.tar.gz",
name = "CPPUtils",
sha256 = "f6464f02ba6c67e36058c3f6f06ff7fe3977340af3fdd350153f4aa15c628a6a",
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., *
* 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 <winuser.h>
#include <cstdlib>
#include <exception>
#include <string>
#endif
// clang-format on
namespace OpenArena {
WindowsLogger::WindowsLogger() {
_type = MESSAGETYPE_ALL;
#ifdef _WIN32
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) {}
WindowsLogger::WindowsLogger(Logger::MessageType type) {
_type = type;
void WindowsLogger::LogError(const MessageType& type, const exception& ex) const {
Logger::LogToDo("Implement OpenArena::WindowsLogger::LogError(MessageType, exception)");
}
void WindowsLogger::Log(const char* message, MessageType type) {
Log(message, "unspecified", type);
void WindowsLogger::LogError(const MessageType& type, const std::string& message, const std::exception& ex) const {
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) {
MessageBox(NULL, message, classification, MB_OK | GetIconFromMessageType(type));
/*
MB_ICONEXCLAMATION - An exclamation point.
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) {
case MESSAGETYPE_ERROR:
return MB_ICONERROR;
case MESSAGETYPE_INFORMATION:
return MB_ICONINFORMATION;
case MESSAGETYPE_DEBUG:
return MB_ICONWARNING;
case MessageType::Debug:
return kDebugMessageTitle;
case MessageType::Error:
return kErrorMessageTitle;
case MessageType::Info:
return kInfoMessageTitle;
case MessageType::Verbose:
return kVerboseMessageTitle;
case MessageType::Warning:
return kWarningMessageTitle;
case MessageType::Wtf:
return kWtfMessageTitle;
default:
return MB_ICONASTERISK;
};
return kUnknownMessageTitle;
}
}
}; // namespace OpenArena
#endif
} // End namespace OpenArena
#ifdef WIN32
namespace OpenArena {}; // namespace OpenArena
#endif

View File

@@ -17,153 +17,29 @@
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#ifndef OpenArena__WindowsLogger_h__
#define OpenArena__WindowsLogger_h__
// clang-format off
#include <cstdint>
#if defined HAVE_CONFIG_H
#include "config.h"
#endif
#include <exception>
#include <string>
#include "logger.h"
// clang-format on
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 {
private:
/*!
* \brief
* 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;
uint32_t GetIcon(const MessageType& type) const;
std::string GetTitle(const MessageType& type) const;
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();
/*!
* \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 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

267
bmp.cpp
View File

@@ -17,18 +17,24 @@
* Free Software Foundation, Inc., *
* 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"
#ifdef WIN32
#pragma warning(disable : 4996)
#endif
#include <cstdint>
#include <cstdio>
#include <memory>
#include "Logger.h"
#include "opengl.h"
// clang-format on
namespace OpenArena {
namespace {
using std::make_shared;
using std::shared_ptr;
using std::string;
using std::to_string;
} // End namespace
#pragma pack(push, 1)
@@ -65,184 +71,187 @@ struct BITMAP_QUAD {
#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) {
printf("Header\n");
printf("Type: %X\nSize: %X\nReserved1: %X\nReserved2: %X\nOffset:%X\n",
header.type,
header.size,
header.reserved1,
header.reserved2,
header.offset);
printf("Type: %X\nSize: %X\nReserved1: %X\nReserved2: %X\nOffset:%X\n", header.type, header.size, header.reserved1,
header.reserved2, header.offset);
}
void PrintBMPInfo(BITMAP_INFO info) {
printf("Info\n");
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(
"SizeImage: %X\nXPelsPerMeter: %X\nYPelsPerMeter: %X\n", info.sizeImage, info.xPelsPerMeter, info.yPelsPerMeter);
printf("SizeImage: %X\nXPelsPerMeter: %X\nYPelsPerMeter: %X\n", info.sizeImage, info.xPelsPerMeter,
info.yPelsPerMeter);
printf("ClrUsed: %X\nClrImportant: %X\n", info.clrUsed, info.clrImportant);
}
TextureImage* LoadBMP(const char* fn) {
// If anything is not perfect return NULL after cleaning up our mess
BitmapImage::~BitmapImage() {}
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
if (!fn) {
return NULL;
Logger::LogDebug("In " + method_name);
// 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...
f = fopen(fn, "rb");
if (f) {
fopen_s(&file, filename.c_str(), "rb");
if (file == nullptr) {
Logger::LogError(method_name + "unable to open file " + filename);
return nullptr;
}
Logger::LogDebug(method_name + "opened file with handle " + to_string((uint64_t)file));
BITMAP_HEADER bmpHeader;
BITMAP_INFO bmpInfo;
BITMAP_QUAD* bmpPallette = NULL;
BITMAP_QUAD* bmpPallette = nullptr;
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;
if (fread(&bmpHeader, sizeof(bmpHeader), 1, file) != 1) {
Logger::LogError(method_name + "Failed to read bitmap header.");
fclose(file);
return nullptr;
}
fread(&bmpInfo, sizeof(bmpInfo), 1, f);
// TODO: Come up with a better endianness check.
uint8_t t[2] = {1, 0};
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 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) {
// This needs to be abstracted somehow
#ifdef WIN32
MessageBox(NULL, "Image width is negative", "ERROR", MB_OK);
#endif
fclose(f);
return NULL;
Logger::LogError("Image width is negative.");
fclose(file);
return nullptr;
}
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;
Logger::LogError("Image width must be a multiple of 8.");
fclose(file);
return nullptr;
}
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;
Logger::LogError("Image height is negative.");
fclose(file);
return nullptr;
}
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;
Logger::LogError("Image height must be a multiple of 8.");
fclose(file);
return nullptr;
}
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;
Logger::LogError("Only 8 and 24 bit uncompressed windows bmp files are currently supported.");
fclose(file);
return nullptr;
}
// 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];
// 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];
fread(bmpPallette, sizeof(BITMAP_QUAD), palletteEntries, f);
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;
}
fseek(f, bmpHeader.offset, SEEK_SET);
fread(tex->data, bytes, 1, f);
Logger::LogDebug("Processing image data.");
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];
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 < pixels; i++) {
for (i = 0; i < num_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;
bmp->data_[i2] = bmpPallette[image[i]].red;
bmp->data_[i2 + 1] = bmpPallette[image[i]].blue;
bmp->data_[i2 + 2] = bmpPallette[image[i]].green;
}
delete[] image;
image = NULL;
image = nullptr;
} 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;
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 tex;
}
return NULL;
return bmp;
}
}; // End namespace OpenArena

34
bmp.h
View File

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

View File

@@ -17,29 +17,19 @@
* Free Software Foundation, Inc., *
* 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 {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
Camera::Camera() {
_position = Vec3f(0, 0, 0);
_heading = Vec3f(0, 0, -1);
_up = Vec3f(0, 1, 0);
}
Camera::Camera() : _position(0, 0, 0), _heading(0, 0, 0), _up(0, 1, 0) {}
void Camera::PositionCamera(double xpos,
double ypos,
double zpos,
double xview,
double yview,
double zview,
double xup,
double yup,
double zup) {
void Camera::PositionCamera(double xpos, double ypos, double zpos, double xview, double yview, double zview, double xup,
double yup, double zup) {
_position = Vec3f(xpos, ypos, zpos);
_heading = Vec3f(xview - xpos, yview - ypos, zview - zpos);
_up = Vec3f(xup, yup, zup).normalized();
@@ -161,5 +151,4 @@ Vec3f Camera::GetForwardVector() {
void Camera::UpdateVectors() {}
#pragma clang diagnostic pop
}; // End namespace OpenArena

372
camera.h
View File

@@ -17,361 +17,121 @@
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#ifndef OpenArena__camera_h__
#define OpenArena__camera_h__
#if defined HAVE_CONFIG_H
// clang-format off
#include "config.h"
#endif
#include <cmath>
#ifdef WIN32
#include <windows.h> //Currently used for mouse stuff this should be replaced by oa_input
#endif
#include "window.h"
// clang-format on
namespace OpenArena {
/*!
* \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,
* Look(), for gluLookAt.
*
* \remarks
*
* \see
*/
/// @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,
/// Look(), for gluLookAt.
class Camera {
public:
/*!
* \brief
* Creates a new Camera object.
*
* 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
/// @brief Creates a new Camera object.
/// Creates a new Camera object located at the origin, pointing at the negative
/// z-axis with up being the positive y-axis.
Camera();
// Camera(const Camera&); //Copy Constructor
/*!
* \brief
* Returns this Camera's position.
*
* \returns
* This Camera's position as a Vec3d vector.
*
* Returns this Camera's position.
*
*/
/// @brief Returns this Camera's position.
/// @return This Camera's position as a Vec3d vector
Vec3f Position();
/*!
* \brief
* Returns the view vector of this camera.
*
* \returns
* The view vector of this camera.
*
* \remarks
*
* \see
*/
/// @brief Returns the view vector of this camera.
/// @return The view vector of this camera.
Vec3d View();
/*!
* \brief
* Returns a vector pointing up with respect to the view.
*
* \returns
* A vector pointing up with respect to the view.
*
* \remarks
*
* \see
*/
/// @brief Returns a vector pointing up with respect to the view.
/// @return A vector pointing up with respect to the view.
Vec3d UpVector();
/*!
* \brief
* Returns 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
*/
/// @brief Returns this Camera's strafe vector.
/// The strafe axis is an axis perpendicular to both the up vector and the view vector.
/// @return This Camera's strafe vector.
Vec3d Strafe();
/*!
* \brief
* Relocates and reorients this Camera.
*
* \param xpos
* The x-coordinate of the new position vector.
*
* \param ypos
* The y-coordinate of the new position vector.
*
* \param zpos
* The z-coordinate of the new position vector.
*
* \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.
/// @param xpos The x-cooridnate of the new position vector.
/// @param ypos The y-coordinate of the new position vector.
/// @param zpos The z-coordinate of the new position vector.
/// @param xview The x-coordinate of the new view vector.
/// @param yview The y-coordiante of the new view vector.
/// @param zview The z-cooridnate 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.
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.
*
* \param pos
* The new position vector.
*
* \param view
* The new view vector.
*
* \param up
* The new up vector.
*
* \remarks
*
* \see
*/
/// @brief Relocates and reorients this Camera.
/// @param pos The new position vector.
/// @param view The new view vector.
/// @param up The new up vector.
void PositionCamera(Vec3d pos, Vec3d view, Vec3d up);
/*!
* \brief
* Rotates the camera a given ammount around a given axis.
*
* \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
*/
/// @brief Rotates the camera a given amount around a given axis.
/// @param angle The number of degrees to rotate. Is this actually degrees not radians?
/// @param axis A vector representing the axis to rotate around.
/// This method passes the arguments to glRotatef().
void RotateView(double angle, Vec3d axis);
/*!
* \brief
* Rotates the camera a given ammount around a given axis.
*
* \param angle
* The number of degrees to rotate.
*
* \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
*/
/// @brief Rotates the camera a given amount around a given axis.
/// @param angle The number of degrees to rotate.
/// @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.
/// The vector should be normalized as the values get passed directly to glRotatef().
void RotateView(double angle, double X, double Y, double Z);
/*!
* \brief
* Updates the view and up vectors based on mouse movement.
*
* \param window
* The Window used to get the mouse coordinates.
*
* \remarks
* This will be removed in favor of some sort of event trigger.
*
* \see
*/
/// @brief Updates the view and up vectors based on mouse movement.
/// @param window The Window used to get the mouse coordinates.
/// This will be removed in favor of some sort of event trigger.
void SetViewByMouse(Window window);
/*!
* \brief
* Moves the camera along its strafe axis a given distance.
*
* \param speed
* The distance to move.
*
* \remarks
*
* \see
*/
/// @brief Moves the camera along its strafe axis a given distance.
/// @param speed The distance to move.
void StrafeCamera(double speed);
// Purpose:
// Moves the camera along it's strafe vector speed units.
/*!
* \brief
* Moves the camera along its view vector a given number of units.
*
* \param speed
* The distance to move the camera.
*
* \remarks
*
* \see
*/
/// @brief Moves the camera along its view vector a given number of units.
/// @param speed The distance to move the camera.
void MoveCamera(double speed);
/*!
* \brief
* Recalculates the strafe vector.
*
* \remarks
*
* \see
*/
/// @brief Recalculates the strafe vector.
void Update();
/*!
* \brief
* Calls gluLookAt to tell OpenGL where to render from.
*
* \remarks
* Uses the position, view, and up vectors.
*
* \see
*/
/// @brief Calls gluLookAt to tell OpenGL where to render from.
/// Uses the position, view, and up vectors.
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);
/*!
* \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);
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();
/*!
* \brief
* 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.
*
* Returns a unit vector pointing to the immediate right of the current view.
* This is the direction of a positive strafe movement.
*
* \remarks
*
* \see
*/
/// @brief Returns a unit vector pointing to the immediate right of the current view.
/// @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. This is the direction of a positive
/// strafe movement.
Vec3f GetRightVector();
/*!
* \brief
* Returns 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.
*
* \remarks
*
* \see
*/
/// @brief Returns a unit vector pointing directly into the current view.
/// @return 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.
Vec3f GetForwardVector();
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., *
* 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 {
PluginManager::PluginManager(void) {}
#define USE_OPENGL
#define USE_WGL
PluginManager::~PluginManager(void) {}
list<Plugin*> PluginManager::GetPluginsOfType(Plugin::Type type) {
return list<Plugin*>();
}
VideoPlugin* PluginManager::GetDefaultVideoPlugin(void) {
return new NullVideoPlugin();
}
} // End namespace OpenArena
#endif // End !defined(OpenArena__config_h__)

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., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#ifndef OpenArena__Plugin_h__
#define OpenArena__Plugin_h__
#if defined HAVE_CONFIG_H
#include "config.h"
#endif
#ifndef OpenArena__console_logger_h__
#define OpenArena__console_logger_h__
// clang-format off
#include "Logger.h"
// clang-format on
namespace OpenArena {
/*!
* \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 {
class ConsoleLogger : public Logger {
public:
/*!
* \brief
* Write brief comment for ~Plugin here.
*
* \throws <exception class>
* 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) {}
ConsoleLogger();
virtual ~ConsoleLogger();
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;
/*!
* \brief
* Write brief comment for InputPlugin here.
*/
enum Type { VideoPlugin, AudioPlugin, InputPlugin };
private:
std::string GetTitle(const MessageType& type) const;
};
} // namespace OpenArena
} // End namespace OpenArena
#endif // End !defined(OpenArena__Plugin_h__)
#endif // End !defined(OpenArena__console_logger_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., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include "ctrls.h"
// clang-format off
#include "ctrls.h"
#include "strmanip.h"
using std::endl;
using std::ostream;
using std::string;
// clang-foramt on
namespace OpenArena {
namespace {
using std::endl;
using std::ostream;
using std::string;
} // End namespace
void ControlScheme::LoadDefaultControlScheme() {
UnBindAll();
Bind(OpenArena::KEY_LBUTTON, ACTION_FORWARD);
Bind(OpenArena::KEY_RBUTTON, ACTION_BACKWARD);
Bind(OpenArena::KEY_LEFT, ACTION_LOOKLEFT);
@@ -184,4 +190,12 @@ bool ControlScheme::IsBound(OpenArena::Keys key, Action action) {
return false;
}
ControlScheme::Action ControlScheme::GetAction(OpenArena::Keys key) {
return keyActions[key];
}
ControlScheme::ControlScheme(){
UnBindAll();
}
} // End namespace OpenArena

10
ctrls.h
View File

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

View File

@@ -17,16 +17,16 @@
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#ifndef OpenArena__geometry_h__
#define OpenArena__geometry_h__
#if defined HAVE_CONFIG_H
// clang-format off
#include "config.h"
#endif
#include "myglTexture.h"
#include "vector.h"
// clang-format on
namespace OpenArena {
class Vertex {
public:
@@ -34,25 +34,12 @@ class Vertex {
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 {
public:
Texture texture;
Triangle();
Texture& texture;
uint32_t texID;
Vertex vertecies[3];
// Vec3f vertecies[3];
// Vec2f texCoords[3];
Vec3f normal;
};

View File

@@ -26,3 +26,23 @@
// 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., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#ifndef OpenArena__image_h__
#define OpenArena__image_h__
#include <cstdint>
#if defined HAVE_CONFIG_H
// clang-format off
#include "config.h"
#endif
#include <cstdint>
#include <memory>
#include "texture.h"
// clang-format on
namespace OpenArena {
/*!
* \brief
* Write brief comment for Image here.
*
* Write detailed description for Image here.
*
* \remarks
* Write remarks for Image here.
*
* \see
* Separate items with the '|' character.
*/
class ImageBase {
public:
enum Type { Unknown, RGB, RGBA };
ImageBase();
virtual ~ImageBase();
virtual std::shared_ptr<uint8_t[]> GetImageData() const;
virtual uint32_t GetBitsPerPixel() const;
virtual uint32_t GetBytesPerPixel() const;
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 {
public:
// 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;
/*!
* \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;
/*!
* \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;
/*!
* \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;
/*!
* \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;
/*!
* \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;
/*!
* \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) {}
};
} // End namespace OpenArena

View File

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

79
keys.h
View File

@@ -17,26 +17,15 @@
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#ifndef OpenArena__keys_h__
#define OpenArena__keys_h__
#if defined HAVE_CONFIG_H
// clang-format off
#include "config.h"
#endif
// clang-format on
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 {
KEY_UNKNOWN = 0,
KEY_BUTTON0,
@@ -149,69 +138,9 @@ enum Keys {
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;
/*!
* \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;
/*!
* \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;
/*!
* \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);
const char* GetKeyName(Keys key);
OpenArena::Keys GetKey(const char* keyName);

254
level.cpp
View File

@@ -17,50 +17,46 @@
* Free Software Foundation, Inc., *
* 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"
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
#ifdef WIN32
#pragma warning(disable : 4996)
#endif
#pragma clang diagnostic pop
using namespace std;
// clang-format on
namespace {
// using std::cout;
using std::endl;
using std::ifstream;
using std::ofstream;
using std::ostringstream;
using std::string;
using std::to_string;
using std::vector;
} // End namespace
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);
showFPS = false;
showConsole = false;
nextLevel = "intro.map";
gamedir = "oa/";
sound = true;
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() {
@@ -71,11 +67,11 @@ Level::~Level() {
}
bool Level::LoadMap(string mapname) {
string method_name = "OpenArena::Level::LoadMap(string) ";
ifstream input;
string readBuffer;
// players.Insert(*defaultPlayer);
Logger::LogDebug(method_name + "Loading map: " + mapname);
mapname = gamedir + "maps/" + mapname;
if (tolower(Right(mapname, 4)) != ".map") mapname = mapname + ".map";
@@ -83,19 +79,13 @@ bool Level::LoadMap(string mapname) {
input.open(mapname.c_str());
if (!input) {
char* tmpChar = new char[mapname.length() + 41];
strcpy(tmpChar, "Unable to load level file ");
strcat(tmpChar, mapname.c_str());
strcat(tmpChar, " doesn't exist.");
// This needs to be abstracted somehow
#ifdef WIN32
MessageBox(NULL, tmpChar, "ERROR", MB_OK | MB_ICONEXCLAMATION);
#endif
delete[] tmpChar;
string message = "Unable to load level file " + mapname + " doesn't exist.";
Logger::LogError(method_name + message);
Logger::LogDebug(method_name + "returning false.");
return false;
} else {
ConsolePrint("map file \"" + mapname + "\" opened successfully");
Logger::LogDebug(method_name + "Map file \"" + mapname + "\" opened successfully.");
ConsolePrint("Map file \"" + mapname + "\" opened successfully.");
}
// Gravity
@@ -138,60 +128,53 @@ bool Level::LoadMap(string mapname) {
}
char lpszNumTriangles[6];
sprintf(lpszNumTriangles, "%d", numTriangles);
ConsolePrint(lpszNumTriangles + string(" triangles successfully read"));
ConsolePrint(lpszNumTriangles + string(" triangles successfully read."));
// Number of textures;
input >> readBuffer;
numTextures = Integer(readBuffer);
Logger::LogDebug("read num_textures = " + to_string(numTextures));
// Texture data
textureNames = new string[numTextures];
for (unsigned int i = 0; i < numTextures; i++) {
input >> textureNames[i];
Logger::LogDebug("read texture name = " + textureNames[i]);
}
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];
sprintf(lpszNumTextures, "%d", numTextures);
ConsolePrint(lpszNumTextures + string(" textures successfully read"));
Logger::LogDebug("about to read bgm from file");
// BGM
input >> bgm;
// Build display list
Logger::LogDebug(string("sound is ") + (sound ? "true" : "false"));
// Sound
if (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 (toupper(bgm[0]) == 'C' && toupper(bgm[1]) == 'D' && toupper(bgm[2]) == 'A') {
bgmCDA = Integer(bgm.substr(3, bgm.length()));
// This needs to be abstracted somehow
#ifdef WIN32
BASS_CDPlay(bgmCDA, 1, 0);
#endif
} else {
bgmCDA = 0;
string tmpstr = gamedir + "music/bgm/" + bgm;
// 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
// This needs to be abstracted somehow
}
}
ConsolePrint("Sound init complete");
} else {
ConsolePrint("Sound disabled");
}
Logger::LogDebug(method_name + "returning true.");
return true;
}
@@ -210,16 +193,7 @@ void Level::SaveMap(string mapname) {
output.open(mapname.c_str());
if (!output) {
char* tmpChar = new char[mapname.length() + 42];
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;
Logger::LogError("Unable to save level file " + mapname + " already exists.");
return;
}
@@ -254,7 +228,75 @@ void Level::SaveMap(string mapname) {
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() {
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();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
@@ -262,15 +304,16 @@ void Level::Render() {
// Move the camera to where the player is
defaultPlayer->camera.Look();
Logger::LogDebug(method_name + "Rendering " + std::to_string(numTriangles) + " triangles.");
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);
// glNormal3f((GLfloat)triangles[i].normal.x, (GLfloat)triangles[i].normal.y,
//(GLfloat)triangles[i].normal.z);
for (uint32_t i2 = 0; i2 < 3; i2++) {
glTexCoord2f(triangles[i].vertecies[i2].textureCoordinates.x, triangles[i].vertecies[i2].textureCoordinates.y);
glVertex3f((GLfloat)triangles[i].vertecies[i2].coordinates.x,
(GLfloat)triangles[i].vertecies[i2].coordinates.y,
glVertex3f((GLfloat)triangles[i].vertecies[i2].coordinates.x, (GLfloat)triangles[i].vertecies[i2].coordinates.y,
(GLfloat)triangles[i].vertecies[i2].coordinates.z);
}
glEnd();
@@ -366,10 +409,7 @@ void Level::UnloadMap() {
}
// Free all map textures
if (!textures.IsEmpty()) {
// TODOiterate over list and delete all entries
}
textures.Clear();
textures.clear();
// Free the array of texture names
if (textureNames) {
@@ -379,26 +419,36 @@ void Level::UnloadMap() {
}
void Level::LoadGLTextures() {
if (_window != NULL) {
/*
GLfloat light[4] = {1.0f,1.0f,1.0f,0.5f};
glLightfv(GL_LIGHT1, GL_AMBIENT, light);
glEnable(GL_LIGHT1);
glEnable(GL_LIGHTING);
*/
textures.Clear();
Logger::LogDebug("In LoadGLTextures");
string file_name;
if (_window != nullptr) {
Logger::LogDebug("_window is not null");
textures.clear();
for (uint32_t i = 0; i < numTextures; i++) {
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;
}
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
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");
}
}
@@ -649,7 +699,6 @@ void Level::LoadConfig() {
bool Level::LoadConfig(string cfgname) {
ifstream input;
string readBuffer;
cfgname = gamedir + "config/" + cfgname;
if (tolower(Right(cfgname, 4)) != ".cfg") cfgname = cfgname + ".cfg";
@@ -728,6 +777,7 @@ void Level::ConsolePrint(string line) {
consoleOutput[i] = consoleOutput[i - 1];
}
consoleOutput[0] = line;
Logger::LogInfo("Console Message: " + line);
}
void Level::SetWindow(Window* window) {
@@ -737,6 +787,4 @@ void Level::SetWindow(Window* window) {
Window* Level::GetWindow() {
return _window;
}
#pragma clang diagnostic pop
} // End namespace OpenArena

61
level.h
View File

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

View File

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

View File

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

68
main.h
View File

@@ -17,12 +17,11 @@
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#ifndef OpenArena__main_h__
#define OpenArena__main_h__
#if defined HAVE_CONFIG_H
// clang-format off
#include "config.h"
#endif
#if defined USE_GLX
#include <GL/gl.h> // Header file for OpenGL32 library
@@ -32,9 +31,9 @@
#elif defined USE_CGL
#error unimplemented method
#elif defined USE_WGL
#include <windows.h>
#include <GL/gl.h> // Header file for OpenGL32 library
#include <GL/glu.h> // Header file for Glu32 library
#include <windows.h>
#endif
#include <math.h>
@@ -49,10 +48,7 @@
#include "vector.h"
#include "window.h"
#include "worlddefs.h"
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunknown-pragmas"
#pragma warning(disable : 4786)
#pragma clang diagnostic pop
// clang-format on
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Variables
@@ -66,7 +62,7 @@ extern OpenArena::Vec2i g_mousePosition;
#ifdef WIN32
extern POINT mpos;
#endif
#endif // OpenArena__main_h__
extern float lastTime; // This will hold the time from the last frame
extern float currentTime;
@@ -76,62 +72,8 @@ extern float currentTime;
// This shouldn't need to be here
// LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); // Declaration for WndProc
/*!
* \brief
* 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
int DrawGLScene(OpenArena::Level* level);

View File

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

View File

@@ -17,31 +17,41 @@
* Free Software Foundation, Inc., *
* 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 "strmanip.h"
#include "texture.h"
#include "tga.h"
// clang-format on
namespace OpenArena {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
namespace {
using std::shared_ptr;
using std::string;
} // End namespace
void FreeGLTexture(GLuint& texture) {
glDeleteTextures(1, &texture);
}
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") {
TextureImage* texImage = NULL;
if ((texImage = LoadBMP(fn.c_str()))) {
Logger::LogDebug(method_name + "Loading a bitmap.");
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);
glBindTexture(GL_TEXTURE_2D, texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexImage2D(
GL_TEXTURE_2D, 0, 3, texImage->sizeX, texImage->sizeY, 0, texImage->type, GL_UNSIGNED_BYTE, texImage->data);
glTexImage2D(GL_TEXTURE_2D, 0, 3, texImage->sizeX, texImage->sizeY, 0, texImage->type, GL_UNSIGNED_BYTE,
texImage->data);
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;
}
} else if (Right(tolower(fn), 4) == ".tga") {
TextureImage* texImage = NULL;
if ((texImage = LoadTGA(fn.c_str()))) {
Logger::LogDebug(method_name + "Loading a tga file.");
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);
glBindTexture(GL_TEXTURE_2D, texture);
glTexImage2D(
GL_TEXTURE_2D, 0, 3, texImage->sizeX, texImage->sizeY, 0, texImage->type, GL_UNSIGNED_BYTE, texImage->data);
glTexImage2D(GL_TEXTURE_2D, 0, 3, texImage->sizeX, texImage->sizeY, 0, texImage->type, GL_UNSIGNED_BYTE,
texImage->data);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_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);
free(texImage);
}
Logger::LogDebug(method_name + "returning true");
return true;
} else {
Logger::LogDebug(method_name + "returning false from 1");
return false;
}
} else {
Logger::LogDebug(method_name + "returning false from 2");
return false;
}
}
#pragma clang diagnostic pop
} // End namespace OpenArena
OpenArena::Window* g_Screen = new OpenArena::Window();
} // End namespace OpenArena

82
mygl.h
View File

@@ -17,93 +17,25 @@
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#ifndef OpenArena__mygl_h__
#define OpenArena__mygl_h__
#if defined HAVE_CONFIG_H
// clang-format off
#include "config.h"
#endif
#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 "opengl.h"
#include "window.h"
using namespace std;
// clang-format on
#ifdef WIN32
// These this is windows specific
static HINSTANCE hInstance; // Application instance
#endif
namespace OpenArena {
// TODO: Move this to behidden in mygl.cpp.
extern OpenArena::Window* g_Screen;
namespace OpenArena {
/*!
* \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.
*/
bool LoadGLTexture(std::string, GLuint&, GLuint = GL_LINEAR, GLuint = GL_LINEAR);
void FreeGLTexture(GLuint&);
}; // namespace OpenArena
#endif
#endif // !defined(OpenArena__mygl_h__)

View File

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

View File

@@ -17,28 +17,17 @@
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#ifndef OpenArena__myglFont_h__
#define OpenArena__myglFont_h__
#if defined HAVE_CONFIG_H
// clang-format off
#include "config.h"
#endif
#include "mygl.h"
// clang-format on
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 {
private:
short screenWidth;
@@ -48,223 +37,16 @@ class Font {
bool status;
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();
/*!
* \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();
/*!
* \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*);
/*!
* \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();
/*!
* \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);
/*!
* \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();
/*!
* \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);
/*!
* \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);
/*!
* \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);
/*!
* \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();
/*!
* \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();
};
} // End namespace OpenArena

View File

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

View File

@@ -17,321 +17,33 @@
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#ifndef OpenArena__myglTexture_h__
#define OpenArena__myglTexture_h__
#if defined HAVE_CONFIG_H
// clang-format off
#include "config.h"
#endif
#include <string>
#include "mygl.h"
using namespace std;
// clang-format on
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 {
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();
/*!
* \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();
/*!
* \brief
* Write brief comment for Filename here.
*
* \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.
*/
std::string Filename() const;
uint32_t ID() const;
bool Load(std::string filename);
bool Load(std::string filename, uint32_t min, uint32_t mag);
void Free();
/*!
* \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();
/*!
* \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&);
bool Loaded() const;
bool operator<(const Texture&) const;
bool operator<=(const Texture&) const;
bool operator==(const Texture&) const;
bool operator!=(const Texture&) const;
bool operator>=(const Texture&) const;
bool operator>(const Texture&) const;
private:
uint32_t minFilter;
@@ -339,5 +51,7 @@ class Texture {
std::string filename;
uint32_t id;
};
extern Texture kUnknownTexture;
} // End namespace OpenArena
#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., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
// clang-format off
#include "player.h"
// clang-format on
namespace OpenArena {
void Player::Load() {}

View File

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

View File

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

275
screen.h
View File

@@ -17,302 +17,39 @@
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#ifndef OpenArena__screen_h__
#define OpenArena__screen_h__
// clang-format off
#include "config.h"
#include <string>
#if defined HAVE_CONFIG_H
#include "config.h"
#endif
using namespace std;
// clang-format on
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 {
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();
/*!
* \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();
/*!
* \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();
/*!
* \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();
/*!
* \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();
/*!
* \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();
/*!
* \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);
/*!
* \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);
/*!
* \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);
/*!
* \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);
/*!
* \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);
/*!
* \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();
/*!
* \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*);
/*!
* \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);
void SetName(std::string);
protected:
short _width;
short _height;
char _colorDepth;
bool _fullscreen;
// public:
string _name;
std::string _name;
};
} // End namespace OpenArena
#endif // End !defined(OpenArena__screen_h__)

View File

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

View File

@@ -17,221 +17,24 @@
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#ifndef OpenArena__strmanip_h__
#define OpenArena__strmanip_h__
#if defined HAVE_CONFIG_H
// clang-format off
#include "config.h"
#endif
#include <cmath>
#include <string>
// clang-format on
using namespace std;
bool Truth(std::string str);
int Integer(std::string str);
float Floating(std::string str);
/*!
* \brief
* Write brief comment for Truth 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 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);
std::string KeyString(uint8_t keyCode);
std::string Right(std::string, uint32_t);
std::string Left(std::string, uint32_t);
std::string tolower(std::string);
std::string toupper(std::string);
std::string word(std::string, uint32_t);
#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., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#ifndef OpenArena__texture_h__
#define OpenArena__texture_h__
#if defined HAVE_CONFIG_H
// clang-format off
#include "config.h"
#endif
// clang-format on
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 {
public:
unsigned char* data;

752
tga.cpp
View File

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

84
tga.h
View File

@@ -17,83 +17,25 @@
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#ifndef OpenArena__tga_h__
#define OpenArena__tga_h__
#if defined HAVE_CONFIG_H
// clang-format off
#include "config.h"
#endif
#include <cstdio>
#include <memory>
#include <string>
#include "image.h"
#include "texture.h"
// clang-format on
namespace OpenArena {
/*!
* \brief
* Write brief comment for TGAHeader here.
*
* Write detailed description for TGAHeader here.
*
* \remarks
* Write remarks for TGAHeader here.
*
* \see
* Separate items with the '|' character.
*/
struct TGAHeader {
uint8_t Header[12]; // File Header To Determine File Type
class TargaImage : public ImageBase {
public:
virtual ~TargaImage();
static std::shared_ptr<TargaImage> FromFile(std::string filename);
};
/*!
* \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
} // End namespace OpenArena
#endif // End !defined OpenArena__tga_h__

View File

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

948
vector.h

File diff suppressed because it is too large Load Diff

View File

@@ -17,5 +17,9 @@
* Free Software Foundation, Inc., *
* 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: git"
#endif // End !defined(OpenArena__version_h__)

View File

@@ -17,14 +17,18 @@
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include "window.h"
#include <OpenGL/gl.h>
#include <OpenGL/glu.h>
// clang-format off
#include "window.h"
#include <windows.h>
#include "opengl.h"
// clang-format on
namespace OpenArena {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
namespace {
using std::string;
} // End namespace
void OpenArena::Window::SwapBuffers() {
#if defined USE_GLX
@@ -106,36 +110,16 @@ bool OpenArena::Window::Open() {
#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);
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);
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);
@@ -164,8 +148,7 @@ bool OpenArena::Window::Open() {
err = CreateNewWindow(kDocumentWindowClass,
kWindowStandardHandlerAttribute | kWindowCloseBoxAttribute | kWindowFullZoomAttribute
| kWindowCollapseBoxAttribute,
&_bounds,
&_window);
&_bounds, &_window);
if (err != noErr) {
return false;
}
@@ -240,8 +223,7 @@ bool OpenArena::Window::Open() {
if (MessageBox(NULL,
"The Requested Fullscreen Mode Is Not Supported By\nYour "
"Video Card. Use Windowed Mode Instead?",
"OpenArena",
MB_YESNO | MB_ICONEXCLAMATION)
"OpenArena", MB_YESNO | MB_ICONEXCLAMATION)
== IDYES)
_fullscreen = false;
else {
@@ -263,18 +245,9 @@ bool OpenArena::Window::Open() {
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))) {
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;
@@ -284,7 +257,7 @@ bool OpenArena::Window::Open() {
1,
PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER,
PFD_TYPE_RGBA,
_colorDepth,
static_cast<BYTE>(_colorDepth),
0,
0,
0,
@@ -526,5 +499,4 @@ Cursor OpenArena::Window::CreateFullscreenCursor() {
return cur;
}
#endif
#pragma clang diagnostic pop
} // End namespace OpenArena

View File

@@ -17,42 +17,18 @@
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#ifndef OpenArena__window_h__
#define OpenArena__window_h__
#if defined HAVE_CONFIG_H
// clang-format off
#include "config.h"
#endif
#include "opengl.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"
// clang-format on
namespace OpenArena {
class Window : public Screen {
public:
@@ -68,43 +44,21 @@ class Window : public Screen {
public:
Window();
~Window();
void Close();
bool Open();
bool Open(string title,
int width,
int height,
int bits,
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
void SetInitializer(Initializer* initializer);
void SetResizer(Resizer* resizer);
void SwapBuffers();
void Resize(uint32_t width, uint32_t height);
Vec2i GetMousePosition();
void SetMousePosition(Vec2i pos);
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);
#ifdef USE_GLX
Display* GetDisplay();
#endif
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
#ifdef USE_WGL
// TODO: move this to opengl/window
HGLRC glContext;
HWND window;
HDC deviceContext;
@@ -117,9 +71,10 @@ class Window : public Screen {
#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 attrListDbl[] = {
GLX_RGBA, GLX_DOUBLEBUFFER, GLX_RED_SIZE, 4, GLX_GREEN_SIZE, 4, GLX_BLUE_SIZE, 4, GLX_DEPTH_SIZE, 16, None};
static int attrListDbl[] = {GLX_RGBA, GLX_DOUBLEBUFFER, GLX_RED_SIZE, 4, GLX_GREEN_SIZE, 4, GLX_BLUE_SIZE,
4, GLX_DEPTH_SIZE, 16, None};
#elif defined USE_WGL
// TODO: Move this to opengl/window.
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
#endif

View File

@@ -17,46 +17,82 @@
* Free Software Foundation, Inc., *
* 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 "mygl.h"
#include "opengl.h"
#include "opengl/window.h"
#include "vector.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;
// link necessary libraries
#pragma comment(lib, "opengl32.lib")
#pragma comment(lib, "glu32.lib")
#pragma comment(lib, "glaux.lib")
#pragma comment(lib, "winmm.lib")
// Ensure CDS_FULLSCREEN is defined
#ifndef CDS_FULLSCREEN
#define CDS_FULLSCREEN 4
#endif
using namespace std;
using OpenArena::WindowsLogger;
using OpenArena::OpenGL::Window;
using std::exception;
using std::make_shared;
using std::string;
using std::to_string;
} // End namespace
void InitControls();
int InitGL(GLvoid);
void ReSizeGLScene(GLsizei width, GLsizei height);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow);
LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
OpenArena::Keys TranslateKey(int keyCode);
void HandleConsoleKeyPress(OpenArena::Keys key);
Keys TranslateKey(int keyCode);
void HandleConsoleKeyPress(Keys key);
Level* level = nullptr;
bool keys[256] = {false};
bool keys2[256] = {false};
bool active = false;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Function Definitions
int DrawGLScene(Level* level) {
level->Render();
g_Screen->SwapBuffers();
return 1;
}
//
// void InitControls()
// Purpose:
// Initializes controls by loading the default control config file "my.cfg".
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) {
level.LoadGLTextures();
level->LoadGLTextures();
glEnable(GL_TEXTURE_2D);
glShadeModel(GL_SMOOTH);
@@ -81,11 +117,11 @@ int InitGL(GLvoid) {
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
/*lighting disabled temporarily
glLightfv(GL_LIGHT1, GL_AMBIENT, level.LightAmbient);
for(index=0; index<level.numLights; index++)
glLightfv(GL_LIGHT1, GL_AMBIENT, level->LightAmbient);
for(index=0; index<level->numLights; index++)
{
glLightfv(GL_LIGHT1, GL_DIFFUSE, level.light[index].color);
glLightfv(GL_LIGHT1, GL_POSITION, level.light[index].coords);
glLightfv(GL_LIGHT1, GL_DIFFUSE, level->light[index].color);
glLightfv(GL_LIGHT1, GL_POSITION, level->light[index].coords);
}
glEnable(GL_LIGHT1);
@@ -140,8 +176,8 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
return 0;
}
case WM_KEYDOWN: {
if (level.showConsole) {
HandleConsoleKeyPress((OpenArena::Keys)TranslateKey(wParam));
if (level->showConsole) {
HandleConsoleKeyPress((Keys)TranslateKey(wParam));
} else {
keys[TranslateKey(wParam)] = true;
}
@@ -191,33 +227,46 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
}
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;
try {
g_Screen = new Window();
DrawEvent::DrawEventHandler* _drawEventHandler = new DrawEvent::DrawEventHandler(level);
KeyPressEvent::KeyPressEventHandler* _keyPressEventHandler = new KeyPressEvent::KeyPressEventHandler();
KeyReleaseEvent::KeyReleaseEventHandler* _keyReleaseEventHandler = new KeyReleaseEvent::KeyReleaseEventHandler();
EventManager* em = new EventManager();
level = new Level(em);
bool done = false;
if (strlen(lpCmdLine)) level.ParseCmds(lpCmdLine);
if (strlen(lpCmdLine)) level->ParseCmds(lpCmdLine);
InitControls();
g_Screen.SetInitializer(new OpenArena::Window::Initializer());
g_Screen.SetResizer(new OpenArena::Window::Resizer());
if (!g_Screen.Open(string(OPENARENA_VERSION),
level.screen.GetWidth(),
level.screen.GetHeight(),
level.screen.GetColorDepth(),
level.screen.GetFullscreen())) {
return 0;
g_Screen->SetInitializer(new Window::Initializer());
g_Screen->SetResizer(new Window::Resizer());
if (!g_Screen->Open(string(OPENARENA_VERSION), g_Screen->GetWidth(), g_Screen->GetHeight(),
g_Screen->GetColorDepth(), g_Screen->GetFullscreen())) {
Logger::LogError("Screen open failed.");
return -1;
}
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");
level->SetWindow(g_Screen);
level->glFont.SetScreenDimensions(g_Screen->GetWidth() * 2, g_Screen->GetHeight() * 2);
if (level->nextLevel == "") {
Logger::LogDebug("Loading intro.map");
level->LoadMap("intro.map");
} else {
level.LoadMap();
Logger::LogDebug("Loading nextLevel: " + level->nextLevel);
level->LoadMap();
}
Logger::LogDebug("About to start main loop.");
while (!done) {
// Logger::LogDebug("in while(!done)");
while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
if (msg.message == WM_QUIT) {
done = true;
@@ -231,291 +280,297 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
if (keys[OpenArena::KEY_ESCAPE]) {
done = true;
} else {
level.defaultPlayer[0].camera.Update();
level->defaultPlayer[0].camera.Update();
if (!level.showConsole) {
if (level.mlook) {
using OpenArena::Vec2i;
Vec2i middleOfScreen = Vec2i(g_Screen.GetWidth() / 2, g_Screen.GetHeight() / 2);
Vec2i mousePosition = g_Screen.GetMousePosition();
if (!level->showConsole) {
if (level->mlook) {
Vec2i middleOfScreen = Vec2i(g_Screen->GetWidth() / 2, g_Screen->GetHeight() / 2);
Vec2i mousePosition = g_Screen->GetMousePosition();
if (mousePosition != middleOfScreen) {
// Vec2i mouseDelta = mousePosition - middleOfScreen;
Vec2i mouseDelta = middleOfScreen - mousePosition;
g_Screen.SetMousePosition(middleOfScreen);
g_Screen->SetMousePosition(middleOfScreen);
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);
level->defaultPlayer[0].camera.RotateHorizontal(horizontalAngle);
level->defaultPlayer[0].camera.RotateVertical(verticalAngle);
}
} else {
g_Screen.SetMousePosition(Vec2i(g_Screen.GetWidth() / 2, g_Screen.GetHeight() / 2));
// SetCursorPos(g_Screen.GetWidth()/2, g_Screen.GetHeight()/2);
g_Screen->SetMousePosition(Vec2i(g_Screen->GetWidth() / 2, g_Screen->GetHeight() / 2));
}
//////////
// Move Backward
if (!level.defaultPlayer->controls.backward.IsEmpty()) {
level.defaultPlayer->controls.backward.FirstPosition();
if (keys[level.defaultPlayer->controls.backward.Retrieve()]) {
level.defaultPlayer->camera.MoveCamera(-level.moveSpeed);
} else {
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);
}
}
}
}
// //////////
// // Move Backward
// if (!level->defaultPlayer->controls.backward.IsEmpty()) {
// level->defaultPlayer->controls.backward.FirstPosition();
// if (keys[level->defaultPlayer->controls.backward.Retrieve()]) {
// level->defaultPlayer->camera.MoveCamera(-level->moveSpeed);
// } else {
// 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);
// }
// }
// }
// }
//////////
// Move forward
if (!level.defaultPlayer->controls.forward.IsEmpty()) {
level.defaultPlayer->controls.forward.FirstPosition();
if (keys[level.defaultPlayer->controls.forward.Retrieve()]) {
level.defaultPlayer->camera.MoveCamera(level.moveSpeed);
} else {
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);
}
}
}
}
// //////////
// // Move forward
// if (!level->defaultPlayer->controls.forward.IsEmpty()) {
// level->defaultPlayer->controls.forward.FirstPosition();
// if (keys[level->defaultPlayer->controls.forward.Retrieve()]) {
// level->defaultPlayer->camera.MoveCamera(level->moveSpeed);
// } else {
// 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 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 {
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);
}
}
}
}
// //////////
// // 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 {
// 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);
// }
// }
// }
// }
//////////
// 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 {
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);
}
}
}
}
// //////////
// // 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 {
// 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 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 {
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 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 {
// 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 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 {
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 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 {
// 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 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 {
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);
}
}
}
}
// //////////
// // 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 {
// 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);
// }
// }
// }
// }
//////////
// 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 {
while (level.defaultPlayer->controls.lookDown.NextPosition()
&& (keys[level.defaultPlayer->controls.lookDown.Retrieve()] != true))
;
{
if (keys[level.defaultPlayer->controls.lookDown.Retrieve()]) {
level.defaultPlayer->camera.RotateView(-level.turnSpeed, 1, 0, 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 {
// while (level->defaultPlayer->controls.lookDown.NextPosition()
// && (keys[level->defaultPlayer->controls.lookDown.Retrieve()] != true))
// ;
// {
// if (keys[level->defaultPlayer->controls.lookDown.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;
}
} else {
while (level.defaultPlayer->controls.toggleFPS.NextPosition()
&& (keys[level.defaultPlayer->controls.toggleFPS.Retrieve()] != true))
;
{
if (keys[level.defaultPlayer->controls.toggleFPS.Retrieve()]) {
if (!keys2[level.defaultPlayer->controls.toggleFPS.Retrieve()]) {
level.showFPS = !level.showFPS;
}
}
}
}
}
// //////////
// // 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;
// }
// } else {
// while (level->defaultPlayer->controls.toggleFPS.NextPosition()
// && (keys[level->defaultPlayer->controls.toggleFPS.Retrieve()] != true))
// ;
// {
// if (keys[level->defaultPlayer->controls.toggleFPS.Retrieve()]) {
// if (!keys2[level->defaultPlayer->controls.toggleFPS.Retrieve()]) {
// level->showFPS = !level->showFPS;
// }
// }
// }
// }
// }
//////////
// Toggle MouseLook
if (!level.defaultPlayer->controls.toggleMouseLook.IsEmpty()) {
level.defaultPlayer->controls.toggleMouseLook.FirstPosition();
if (keys[level.defaultPlayer->controls.toggleMouseLook.Retrieve()]) {
if (keys2[level.defaultPlayer->controls.toggleMouseLook.Retrieve()]) {
level.mlook = !level.mlook;
}
} else {
while (level.defaultPlayer->controls.toggleMouseLook.NextPosition()
&& (keys[level.defaultPlayer->controls.toggleMouseLook.Retrieve()] != true))
;
{
if (keys[level.defaultPlayer->controls.toggleMouseLook.Retrieve()]) {
if (keys2[level.defaultPlayer->controls.toggleMouseLook.Retrieve()]) {
level.mlook = !level.mlook;
}
}
}
}
}
// //////////
// // Toggle MouseLook
// if (!level->defaultPlayer->controls.toggleMouseLook.IsEmpty()) {
// level->defaultPlayer->controls.toggleMouseLook.FirstPosition();
// if (keys[level->defaultPlayer->controls.toggleMouseLook.Retrieve()]) {
// if (keys2[level->defaultPlayer->controls.toggleMouseLook.Retrieve()]) {
// level->mlook = !level->mlook;
// }
// } else {
// while (level->defaultPlayer->controls.toggleMouseLook.NextPosition()
// && (keys[level->defaultPlayer->controls.toggleMouseLook.Retrieve()] != true))
// ;
// {
// if (keys[level->defaultPlayer->controls.toggleMouseLook.Retrieve()]) {
// if (keys2[level->defaultPlayer->controls.toggleMouseLook.Retrieve()]) {
// level->mlook = !level->mlook;
// }
// }
// }
// }
// }
//////////
// Toggle Console
if (!level.defaultPlayer[0].controls.toggleConsole.IsEmpty()) {
level.defaultPlayer[0].controls.toggleConsole.FirstPosition();
if (keys[level.defaultPlayer[0].controls.toggleConsole.Retrieve()]) {
if (!keys2[level.defaultPlayer[0].controls.toggleConsole.Retrieve()]) {
level.showConsole = !level.showConsole;
keys2[level.defaultPlayer[0].controls.toggleConsole.Retrieve()] = true;
}
} else {
while (level.defaultPlayer[0].controls.toggleConsole.NextPosition()
&& (keys[level.defaultPlayer[0].controls.toggleConsole.Retrieve()] != true))
;
{
if (keys[level.defaultPlayer[0].controls.toggleConsole.Retrieve()]) {
if (!keys2[level.defaultPlayer[0].controls.toggleConsole.Retrieve()]) {
level.showConsole = !level.showConsole;
keys2[level.defaultPlayer[0].controls.toggleConsole.Retrieve()] = true;
}
}
}
}
}
// //////////
// // Toggle Console
// if (!level->defaultPlayer[0].controls.toggleConsole.IsEmpty()) {
// level->defaultPlayer[0].controls.toggleConsole.FirstPosition();
// if (keys[level->defaultPlayer[0].controls.toggleConsole.Retrieve()]) {
// if (!keys2[level->defaultPlayer[0].controls.toggleConsole.Retrieve()]) {
// level->showConsole = !level->showConsole;
// keys2[level->defaultPlayer[0].controls.toggleConsole.Retrieve()] = true;
// }
// } else {
// while (level->defaultPlayer[0].controls.toggleConsole.NextPosition()
// && (keys[level->defaultPlayer[0].controls.toggleConsole.Retrieve()] != true))
// ;
// {
// if (keys[level->defaultPlayer[0].controls.toggleConsole.Retrieve()]) {
// if (!keys2[level->defaultPlayer[0].controls.toggleConsole.Retrieve()]) {
// level->showConsole = !level->showConsole;
// keys2[level->defaultPlayer[0].controls.toggleConsole.Retrieve()] = true;
// }
// }
// }
// }
// }
//////////
// 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;
// //////////
// // 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();
}
} 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();
level->Render();
//
}
}
g_Screen.SwapBuffers();
// Why the hell are we swapping buffers even if the window is not active?
g_Screen->SwapBuffers();
if (keys[OpenArena::KEY_F1]) {
keys[OpenArena::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())) {
return 0;
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.UnloadMap();
g_Screen.Close();
} catch (const exception& ex) {
Logger::LogWtf("Unhandled exception", ex);
} catch (...) {
Logger::LogWtf("Unhandled exception");
}
Logger::LogDebug("level->UnloadMap()");
level->UnloadMap();
g_Screen->Close();
Logger::LogDebug("g_Screen->Close()");
Logger::LogDebug("Exiting with msg.wParam " + to_string(msg.wParam));
return (msg.wParam);
}
OpenArena::Keys TranslateKey(int keyCode) {
Keys TranslateKey(int keyCode) {
switch (keyCode) {
case VK_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
level.defaultPlayer[0].controls.toggleConsole.FirstPosition();
if (key == level.defaultPlayer[0].controls.toggleConsole.Retrieve()) {
level.showConsole = false;
} else {
while (level.defaultPlayer[0].controls.toggleConsole.NextPosition() && level.showConsole) {
if (level.defaultPlayer[0].controls.toggleConsole.Retrieve() == key) {
level.showConsole = false;
}
}
if (level->defaultPlayer->controls.GetAction(key) == ControlScheme::ACTION_TOGGLE_CONSOLE) {
level->showConsole = false;
}
switch (key) {
case OpenArena::KEY_SHIFT:
keys[OpenArena::KEY_SHIFT] = true;
break;
case OpenArena::KEY_RETURN:
level.UpdateConsole('\n');
level->UpdateConsole('\n');
break;
case OpenArena::KEY_SPACE:
printf("hello");
level.UpdateConsole(' ');
level->UpdateConsole(' ');
break;
case OpenArena::KEY_BACK:
level.UpdateConsole(OpenArena::KEY_BACK);
level->UpdateConsole(OpenArena::KEY_BACK);
break;
default:
char ascii = OpenArena::KeyToASCII(key, keys[OpenArena::KEY_SHIFT]);
char ascii = KeyToASCII(key, keys[OpenArena::KEY_SHIFT]);
if (ascii != '\0') {
level.UpdateConsole(ascii);
level->UpdateConsole(ascii);
}
}
}

View File

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

8
x11.h
View File

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