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.
parent
b1efc3ef74
commit
0142296949
|
@ -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.
|
|
@ -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.
|
|
@ -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
|
||||
|
|
|
@ -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 = "<group>";
|
||||
};
|
||||
20FC421D1AA4607B0083B64C /* States */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
20FC421E1AA460960083B64C /* MenuState.cpp */,
|
||||
20FC421F1AA460960083B64C /* MenuState.hpp */,
|
||||
);
|
||||
name = States;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
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;
|
||||
};
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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 = "<group>";
|
||||
};
|
||||
20FC41ED1AA45D650083B64C /* States */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
20FC41EF1AA45D880083B64C /* MenuState.cpp */,
|
||||
20FC41F01AA45D880083B64C /* MenuState.hpp */,
|
||||
);
|
||||
name = States;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
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;
|
||||
};
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
22
src/Core.hpp
22
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 <vector>
|
||||
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<State*> states; // our record of states
|
||||
// Audio *audio_service;
|
||||
// Net *net_service;
|
||||
};
|
||||
|
|
|
@ -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 <vector>
|
||||
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; // state(s) of this state
|
||||
private:
|
||||
};
|
||||
#endif
|
|
@ -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;
|
||||
}
|
||||
|
|
@ -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
|
Loading…
Reference in New Issue