From 01422969492e7614704dacbbc180d55fb40d3111 Mon Sep 17 00:00:00 2001 From: kts Date: Mon, 2 Mar 2015 01:18:01 -0800 Subject: [PATCH] Added State class and MenuState subclass. Notes added for GUI and STATES in root. iOS, OS X, android, and Linux build environments now use include directories for src/ and src/states. This is to prevent excessive clutter in the src/ directory - although some might say that point was passed long ago. --- GUI | 23 +++++++++++++++++++ STATES | 11 +++++++++ build/android/jni/src/Android.mk | 5 ++++ .../Roll them Bones.xcodeproj/project.pbxproj | 17 ++++++++++++++ build/linux/Makefile | 2 +- .../Roll them Bones.xcodeproj/project.pbxproj | 15 ++++++++++++ src/Core.cpp | 1 + src/Core.hpp | 22 ++++++++++-------- src/State.hpp | 23 +++++++++++++++++++ src/states/MenuState.cpp | 19 +++++++++++++++ src/states/MenuState.hpp | 19 +++++++++++++++ 11 files changed, 147 insertions(+), 10 deletions(-) create mode 100644 GUI create mode 100644 STATES create mode 100644 src/State.hpp create mode 100644 src/states/MenuState.cpp create mode 100644 src/states/MenuState.hpp diff --git a/GUI b/GUI new file mode 100644 index 0000000..fb4a87f --- /dev/null +++ b/GUI @@ -0,0 +1,23 @@ +GUI +---------------- +As a first principle, the GUI shall accept and process coordinate inputs as floats normalized between 0 and 1. Coordinates may also be provided as integers, whereupon they shall be normalized by v_width and v_height as defined in Core. + +GUI Elements shall be scaled and position based upon the same normalized coordinate inputs. + +These normalized values are tied strictly to the size of the screen as returned by v_width and v_height as defined in Core. + +Creation +-------- +Each GUI element shall be created via the GUI, which then in turn creates a new RenderObject() for the UI RenderScene as defined in Core. + +Each GUI element shall rely on a generated texture that should contain visuals to indicate the function of the element. + +Modification +-------- +GUI elements may have their sizes, positions, and textures modified. Texture modifications, which stem from changes in element content, cause the RenderObject's referenced texture to be updated with the new texture source. + +Destruction +-------- +GUI elements should be requested to be destroyed by the original context that requested their creation. + +On GUI service destruction, as would be triggered by the closing of the program, all GUI elements and their corresponding RenderObjects will be destroyed. diff --git a/STATES b/STATES new file mode 100644 index 0000000..77d95f0 --- /dev/null +++ b/STATES @@ -0,0 +1,11 @@ +States +---------------- +States are the manner through which the program's behavioral logic is divided. Each State refers to and communicates to the services provided by Core. + +Within Core, a list of states is kept. Only the top-most state is considered as active and processed. + +Each state must be capable of releasing resources and reacquiring resources when activated or deactivated. These functions are: + * onRise - called on activation, reacquires resources such as textures, vbos, sound assets, etc. + * onCede - called on deactivation, frees loaded resources + +This functionality is for two reasons. The first is that it allows efficient resource usage on all platforms by freeing or releasing resources that are no longer immediately used while also being capable of swiftly reloading resources when a state is reactivated. The second reason is for mobile platforms, as platforms such as iOS require portions of the OpenGL environment to be freed when the application goes to the background. diff --git a/build/android/jni/src/Android.mk b/build/android/jni/src/Android.mk index 257cc86..b74c492 100755 --- a/build/android/jni/src/Android.mk +++ b/build/android/jni/src/Android.mk @@ -7,6 +7,8 @@ LOCAL_MODULE := main SDL_PATH := ../SDL2 LOCAL_C_INCLUDES := $(LOCAL_PATH)/$(SDL_PATH)/include +LOCAL_C_INCLUDES += $(LOCAL_PATH)/../../../../src +LOCAL_C_INCLUDES += $(LOCAL_PATH)/../../../../src/states # Add your application source files here... LOCAL_SRC_FILES := $(SDL_PATH)/src/main/android/SDL_android_main.c \ @@ -46,6 +48,9 @@ LOCAL_SRC_FILES := $(SDL_PATH)/src/main/android/SDL_android_main.c \ ../../../../src/common.hpp \ ../../../../src/Core.cpp \ ../../../../src/Core.hpp \ + ../../../../src/State.hpp \ + ../../../../src/states/MenuState.cpp \ + ../../../../src/states/MenuState.hpp \ ../../../../src/main.cpp LOCAL_SHARED_LIBRARIES := SDL2 diff --git a/build/ios/Roll them Bones.xcodeproj/project.pbxproj b/build/ios/Roll them Bones.xcodeproj/project.pbxproj index beab587..932e698 100755 --- a/build/ios/Roll them Bones.xcodeproj/project.pbxproj +++ b/build/ios/Roll them Bones.xcodeproj/project.pbxproj @@ -39,6 +39,7 @@ 20F746691AA27B8C00F5846A /* Asset.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 20F746631AA27B8C00F5846A /* Asset.cpp */; }; 20F7466A1AA27B8C00F5846A /* AssetCache.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 20F746651AA27B8C00F5846A /* AssetCache.cpp */; }; 20F7466B1AA27B8C00F5846A /* AssetManager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 20F746671AA27B8C00F5846A /* AssetManager.cpp */; }; + 20FC42201AA460960083B64C /* MenuState.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 20FC421E1AA460960083B64C /* MenuState.cpp */; }; 20FD2D3B1A67470A00B32F7B /* main.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 20FD2D3A1A67470A00B32F7B /* main.cpp */; }; 28FD15000DC6FC520079059D /* OpenGLES.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 28FD14FF0DC6FC520079059D /* OpenGLES.framework */; }; 28FD15080DC6FC5B0079059D /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 28FD15070DC6FC5B0079059D /* QuartzCore.framework */; }; @@ -183,6 +184,9 @@ 20F746671AA27B8C00F5846A /* AssetManager.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = AssetManager.cpp; path = ../../src/AssetManager.cpp; sourceTree = SOURCE_ROOT; }; 20F746681AA27B8C00F5846A /* AssetManager.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = AssetManager.hpp; path = ../../src/AssetManager.hpp; sourceTree = SOURCE_ROOT; }; 20F7468F1AA3265900F5846A /* HashTable.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = HashTable.hpp; path = ../../src/HashTable.hpp; sourceTree = SOURCE_ROOT; }; + 20FC421E1AA460960083B64C /* MenuState.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = MenuState.cpp; path = ../../src/states/MenuState.cpp; sourceTree = SOURCE_ROOT; }; + 20FC421F1AA460960083B64C /* MenuState.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = MenuState.hpp; path = ../../src/states/MenuState.hpp; sourceTree = SOURCE_ROOT; }; + 20FC42231AA460BC0083B64C /* State.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = State.hpp; path = ../../src/State.hpp; sourceTree = SOURCE_ROOT; }; 20FD2D3A1A67470A00B32F7B /* main.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = main.cpp; path = ../../src/main.cpp; sourceTree = SOURCE_ROOT; }; 28FD14FF0DC6FC520079059D /* OpenGLES.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = OpenGLES.framework; path = System/Library/Frameworks/OpenGLES.framework; sourceTree = SDKROOT; }; 28FD15070DC6FC5B0079059D /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; }; @@ -337,6 +341,8 @@ 20A7A9131A89F8F600EDC1A0 /* Classes */ = { isa = PBXGroup; children = ( + 20FC42231AA460BC0083B64C /* State.hpp */, + 20FC421D1AA4607B0083B64C /* States */, 20F7468F1AA3265900F5846A /* HashTable.hpp */, 20F746631AA27B8C00F5846A /* Asset.cpp */, 20F746641AA27B8C00F5846A /* Asset.hpp */, @@ -380,6 +386,15 @@ name = "Other Sources"; sourceTree = ""; }; + 20FC421D1AA4607B0083B64C /* States */ = { + isa = PBXGroup; + children = ( + 20FC421E1AA460960083B64C /* MenuState.cpp */, + 20FC421F1AA460960083B64C /* MenuState.hpp */, + ); + name = States; + sourceTree = ""; + }; 29B97314FDCFA39411CA2CEA /* CustomTemplate */ = { isa = PBXGroup; children = ( @@ -518,6 +533,7 @@ 20F746691AA27B8C00F5846A /* Asset.cpp in Sources */, 20F7466A1AA27B8C00F5846A /* AssetCache.cpp in Sources */, 20F7466B1AA27B8C00F5846A /* AssetManager.cpp in Sources */, + 20FC42201AA460960083B64C /* MenuState.cpp in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -584,6 +600,7 @@ OTHER_CFLAGS = ""; PREBINDING = NO; SDKROOT = iphoneos; + USER_HEADER_SEARCH_PATHS = "../../src/**"; }; name = Release; }; diff --git a/build/linux/Makefile b/build/linux/Makefile index 8383ad0..fca74f3 100644 --- a/build/linux/Makefile +++ b/build/linux/Makefile @@ -10,7 +10,7 @@ else endif CXX=g++ DEBUG=-g -CXXFLAGS+=$(DEBUG) -Wall `sdl2-config --cflags` -c +CXXFLAGS+=$(DEBUG) -Wall `sdl2-config --cflags` -I../../src -I../../src/states -c LDFLAGS+= -Wall -L../../../sdl/$(LIB_DIR) -Wl,-rpath=$(LIB_DIR)/ -lSDL2 -lpthread -Wl,--no-undefined -lm -ldl -pthread -lrt -Wl,-Bstatic -lGLEW -Wl,-Bdynamic -lGL VPATH=../../src BINARY=RtB$(BITS) diff --git a/build/osx/Roll them Bones.xcodeproj/project.pbxproj b/build/osx/Roll them Bones.xcodeproj/project.pbxproj index f7ae708..f3fc63c 100644 --- a/build/osx/Roll them Bones.xcodeproj/project.pbxproj +++ b/build/osx/Roll them Bones.xcodeproj/project.pbxproj @@ -38,6 +38,7 @@ 20E3F2941A8CE8470071FD41 /* Log.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 20E3F2901A8CE8470071FD41 /* Log.cpp */; }; 20E3F2951A8CE8470071FD41 /* Mesh.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 20E3F2921A8CE8470071FD41 /* Mesh.cpp */; }; 20F746501AA1DE0F00F5846A /* AssetCache.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 20F7464E1AA1DE0F00F5846A /* AssetCache.cpp */; }; + 20FC41F11AA45D880083B64C /* MenuState.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 20FC41EF1AA45D880083B64C /* MenuState.cpp */; }; 8D11072F0486CEB800E47090 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */; }; /* End PBXBuildFile section */ @@ -118,6 +119,8 @@ 20F7464E1AA1DE0F00F5846A /* AssetCache.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = AssetCache.cpp; path = ../../src/AssetCache.cpp; sourceTree = SOURCE_ROOT; }; 20F7464F1AA1DE0F00F5846A /* AssetCache.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = AssetCache.hpp; path = ../../src/AssetCache.hpp; sourceTree = SOURCE_ROOT; }; 20F746731AA325C000F5846A /* HashTable.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = HashTable.hpp; path = ../../src/HashTable.hpp; sourceTree = SOURCE_ROOT; }; + 20FC41EF1AA45D880083B64C /* MenuState.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = MenuState.cpp; path = ../../src/states/MenuState.cpp; sourceTree = SOURCE_ROOT; }; + 20FC41F01AA45D880083B64C /* MenuState.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = MenuState.hpp; path = ../../src/states/MenuState.hpp; sourceTree = SOURCE_ROOT; }; 8D1107320486CEB800E47090 /* Roll them Bones.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Roll them Bones.app"; sourceTree = BUILT_PRODUCTS_DIR; }; /* End PBXFileReference section */ @@ -139,6 +142,7 @@ 080E96DDFE201D6D7F000001 /* Classes */ = { isa = PBXGroup; children = ( + 20FC41ED1AA45D650083B64C /* States */, 20F746731AA325C000F5846A /* HashTable.hpp */, 20F7464E1AA1DE0F00F5846A /* AssetCache.cpp */, 20F7464F1AA1DE0F00F5846A /* AssetCache.hpp */, @@ -250,6 +254,15 @@ path = shaders; sourceTree = ""; }; + 20FC41ED1AA45D650083B64C /* States */ = { + isa = PBXGroup; + children = ( + 20FC41EF1AA45D880083B64C /* MenuState.cpp */, + 20FC41F01AA45D880083B64C /* MenuState.hpp */, + ); + name = States; + sourceTree = ""; + }; 29B97314FDCFA39411CA2CEA /* INDIE */ = { isa = PBXGroup; children = ( @@ -378,6 +391,7 @@ 205183C71A9F324700DE49E9 /* AssetManager.cpp in Sources */, 205183CC1A9F330000DE49E9 /* Asset.cpp in Sources */, 20F746501AA1DE0F00F5846A /* AssetCache.cpp in Sources */, + 20FC41F11AA45D880083B64C /* MenuState.cpp in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -453,6 +467,7 @@ ONLY_ACTIVE_ARCH = YES; PREBINDING = NO; SDKROOT = ""; + USER_HEADER_SEARCH_PATHS = "../../src/**"; }; name = Release; }; diff --git a/src/Core.cpp b/src/Core.cpp index db6e493..9a73577 100644 --- a/src/Core.cpp +++ b/src/Core.cpp @@ -9,6 +9,7 @@ Core is somewhat like a service locator, but with larger engine capabilities - i #include "RenderCamera.hpp" #include "RenderSet.hpp" #include "RenderObject.hpp" +#include "MenuState.hpp" Core core; diff --git a/src/Core.hpp b/src/Core.hpp index 4419787..8d226f0 100644 --- a/src/Core.hpp +++ b/src/Core.hpp @@ -8,6 +8,8 @@ Core is somewhat like a service locator, but with larger engine capabilities - i #include "common.hpp" #include "RenderScene.hpp" #include "AssetManager.hpp" +#include "State.hpp" +#include class Core { public: Core(); @@ -23,16 +25,18 @@ class Core { AssetManager *getAssetManager(); // Audio* getAudio(); // Net* getNet(); - unsigned int flags; // Core state flags + // Gui* getGui(); + unsigned int flags; // Core state flags private: - SDL_Window *v_window; // Our window - SDL_GLContext v_context; // OpenGL context - GLint v_fbo; // window framebuffer object - int v_width; // width of our display - int v_height; // height of our display - int v_flags; // video flags - RenderScene *scene; // our current render scene - AssetManager *asset_manager; + SDL_Window *v_window; // Our window + SDL_GLContext v_context; // OpenGL context + GLint v_fbo; // window framebuffer object + int v_width; // width of our display + int v_height; // height of our display + int v_flags; // video flags + RenderScene *scene; // our current render scene + AssetManager *asset_manager; // our asset manager service + std::vector states; // our record of states // Audio *audio_service; // Net *net_service; }; diff --git a/src/State.hpp b/src/State.hpp new file mode 100644 index 0000000..e5f357a --- /dev/null +++ b/src/State.hpp @@ -0,0 +1,23 @@ +/* ================================================================ +State +---------------- +State.hpp and State.cpp describe and define the State class. + +A State is, as indicated by the name, a collection of data and functionality that govern a given state of the program. All States are held by Core and iterated through from last to first. +================================================================ */ +#ifndef STATE_HPP +#define STATE_HPP +#include +class State { + friend class Core; + public: + State() {}; + ~State() {}; + protected: + virtual float doProcess(float delta) { return 0.0f; }; + virtual int onCede() { return 0; }; + virtual int onRise() { return 0; }; + std::vector state; // state(s) of this state + private: +}; +#endif diff --git a/src/states/MenuState.cpp b/src/states/MenuState.cpp new file mode 100644 index 0000000..f7449bb --- /dev/null +++ b/src/states/MenuState.cpp @@ -0,0 +1,19 @@ +#include "MenuState.hpp" +/* ======== Construction and Destruction ======== */ +MenuState::MenuState() { + +} +MenuState::~MenuState() { + +} +/* ======== State functions ======== */ +float MenuState::doProcess(float delta) { + return 0.0f; +} +int MenuState::onCede() { + return 0; +} +int MenuState::onRise() { + return 0; +} + diff --git a/src/states/MenuState.hpp b/src/states/MenuState.hpp new file mode 100644 index 0000000..bd89b2e --- /dev/null +++ b/src/states/MenuState.hpp @@ -0,0 +1,19 @@ +/* ================================================================ +MenuState +---------------- +MenuState.cpp/MenuState.hpp provide the Main Menu state that the program first attempts to open. +================================================================ */ +#ifndef MENUSTATE_HPP +#define MENUSTATE_HPP +#include "State.hpp" +class MenuState : public State { + friend class Core; + public: + MenuState(); + ~MenuState(); + protected: + virtual float doProcess(float delta); + virtual int onCede(); + virtual int onRise(); +}; +#endif