Skip to content

Instantly share code, notes, and snippets.

View terryjsmith's full-sized avatar

Terry Smith terryjsmith

View GitHub Profile
@terryjsmith
terryjsmith / gist:1893868
Created February 23, 2012 17:16
Testing PHP class definitions
<?php
var_dump(class_exists('TestClass')); die;
class TestClass {
}
@terryjsmith
terryjsmith / image.php
Last active December 22, 2015 09:48
Automatically resize an image to the browser window width and height to use as a background image (crops from the center for different resolutions, uses jQuery).
<script type="text/javascript">
// Adding an extra 10% in here because both iPhone and Android are repeating the background despite
// the no-repeat and this fixes it
$('body').css('background', "url('/image.php?w=" + ($(window).width() * 1.1) + "&h=" + ($(window).height() * 1.1) + "')");
</script>
@terryjsmith
terryjsmith / component.h
Last active August 29, 2015 14:06
Evolution Component Class
class Component {
public:
Component() : next(0) {};
~Component();
// A stub function that will help us determine this class's type later
virtual void stub() {}
public:
Component* next;
@terryjsmith
terryjsmith / system.h
Last active August 29, 2015 14:06
Evolution System class
class System {
public:
System();
~System();
// Add a new entity to this system by its component
void AddComponent(Component* component);
// Remove an entity by its component
void RemoveComponent(Component* component);
@terryjsmith
terryjsmith / entity.h
Created September 27, 2014 23:42
Evolution Entity class
class Entity {
public:
Entity();
~Entity();
public:
void AddComponent(Component* component);
template<class T>
Component* GetComponent() {
@terryjsmith
terryjsmith / gist:d9a3a610f0a9dd36ca51
Last active August 29, 2015 14:06
Entity GetComponent Example
Renderable* renderable = (Renderable*)entity->GetComponent<Renderable>();
@terryjsmith
terryjsmith / renderable.h
Last active August 29, 2015 14:06
Evolution Renderable class
class Renderable : public Component {
public:
Renderable();
~Renderable();
public:
// Position in world space
glm::vec3 position;
// Local rotation
@terryjsmith
terryjsmith / rendersystem.h
Last active August 29, 2015 14:06
Evolution RenderSystem class
class RenderSystem : System {
public:
RenderSystem();
~RenderSystem();
// Initialize/shut down the render system
void Initialize();
void Shutdown();
// Our main update function
@terryjsmith
terryjsmith / rendersystem.cpp
Last active August 29, 2015 14:06
RenderSystem Implementation
#include <GL/glew.h>
#include <GLFW/glfw3.h>
#include <glm/glm.hpp>
#include <glm/gtc/quaternion.hpp>
#include <error.h>
#include <component.h>
#include <system.h>
#include <rendersystem.h>
#include <renderable.h>
@terryjsmith
terryjsmith / main.cpp
Created September 28, 2014 00:40
Early main loop
/* INCLUDES */
#include <GLFW/glfw3.h>
#include <component.h>
#include <system.h>
#include <rendersystem.h>
/* GLOBAL VARIABLES */