Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

init

  • Loading branch information...
commit aed0280143f9623f824b447facf270ef57a83809 0 parents
Brian Robertson authored
Showing with 3,497 additions and 0 deletions.
  1. +12 −0 RougeMUD-Client/being.h
  2. BIN  RougeMUD-Client/data/dwarf.bmp
  3. +2 −0  RougeMUD-Client/data/img.init
  4. BIN  RougeMUD-Client/data/menu.bmp
  5. +124 −0 RougeMUD-Client/doc/Lua Environment.txt
  6. +11 −0 RougeMUD-Client/doc/UI Mods.txt
  7. +108 −0 RougeMUD-Client/doc/UI Objects Overview.txt
  8. +14 −0 RougeMUD-Client/doc/interface.txt
  9. +155 −0 RougeMUD-Client/game.cpp
  10. +52 −0 RougeMUD-Client/game.h
  11. +219 −0 RougeMUD-Client/luaenv.cpp
  12. +31 −0 RougeMUD-Client/luaenv.h
  13. +154 −0 RougeMUD-Client/main.cpp
  14. +93 −0 RougeMUD-Client/ns_game.cpp
  15. +47 −0 RougeMUD-Client/ns_game.h
  16. +5 −0 RougeMUD-Client/ns_state_game.cpp
  17. +28 −0 RougeMUD-Client/ns_state_game.h
  18. +45 −0 RougeMUD-Client/object.cpp
  19. +37 −0 RougeMUD-Client/object.h
  20. +25 −0 RougeMUD-Client/object_button.cpp
  21. +18 −0 RougeMUD-Client/object_button.h
  22. +262 −0 RougeMUD-Client/object_frame.cpp
  23. +24 −0 RougeMUD-Client/object_frame.h
  24. +124 −0 RougeMUD-Client/object_globalregion.cpp
  25. +22 −0 RougeMUD-Client/object_globalregion.h
  26. +30 −0 RougeMUD-Client/object_image.cpp
  27. +19 −0 RougeMUD-Client/object_image.h
  28. +765 −0 RougeMUD-Client/object_region.cpp
  29. +42 −0 RougeMUD-Client/object_region.h
  30. +25 −0 RougeMUD-Client/object_secure.cpp
  31. +18 −0 RougeMUD-Client/object_secure.h
  32. +34 −0 RougeMUD-Client/object_surface.cpp
  33. +22 −0 RougeMUD-Client/object_surface.h
  34. +30 −0 RougeMUD-Client/object_text.cpp
  35. +19 −0 RougeMUD-Client/object_text.h
  36. +25 −0 RougeMUD-Client/object_worldview.cpp
  37. +19 −0 RougeMUD-Client/object_worldview.h
  38. +24 −0 RougeMUD-Client/state.cpp
  39. +23 −0 RougeMUD-Client/state.h
  40. +132 −0 RougeMUD-Client/state_game.cpp
  41. +35 −0 RougeMUD-Client/state_game.h
  42. +83 −0 RougeMUD-Client/state_login.cpp
  43. +25 −0 RougeMUD-Client/state_login.h
  44. +58 −0 RougeMUD-Client/test.lua
  45. +13 −0 RougeMUD-Client/texture.h
  46. +35 −0 RougeMUD-Client/timer.cpp
  47. +20 −0 RougeMUD-Client/timer.h
  48. +13 −0 RougeMUD-server/being.h
  49. +88 −0 RougeMUD-server/game.cpp
  50. +37 −0 RougeMUD-server/game.h
  51. +81 −0 RougeMUD-server/main.cpp
  52. +87 −0 RougeMUD-server/ns_game.cpp
  53. +26 −0 RougeMUD-server/ns_game.h
  54. +35 −0 RougeMUD-server/timer.cpp
  55. +22 −0 RougeMUD-server/timer.h
12 RougeMUD-Client/being.h
@@ -0,0 +1,12 @@
+#ifndef BEING_STRUCT
+#define BEING_STRUCT
+
+#include <string>
+using namespace std;
+
+typedef struct
+{
+ int x, y;
+}Being;
+
+#endif
BIN  RougeMUD-Client/data/dwarf.bmp
Binary file not shown
2  RougeMUD-Client/data/img.init
@@ -0,0 +1,2 @@
+data/dwarf.bmp 8 11
+data/menu.bmp 247 46
BIN  RougeMUD-Client/data/menu.bmp
Binary file not shown
124 RougeMUD-Client/doc/Lua Environment.txt
@@ -0,0 +1,124 @@
+_G =
+{
+ ["Print"] = function,
+ ["CreateFrame"] = function,
+ ["GetFrame"] = function,
+ ["GlobalRegion"] =
+ {
+ ["Show"] = function,
+ ["Hide"] = function,
+ ["SetPoint"] = function,
+ ["DelPoint"] = function,
+ ["GetPoint"] = function,
+ ["GetPointCount"] = function,
+ },
+ ["WorldView"] =
+ {
+ },
+ [typical object] =
+ {
+ [0] = userdata,
+ ["SetEventHandler"] = function,
+ ["NoticeEvent"] = function,
+ ["NoticeAllEvents"] = function,
+ ["IgnoreEvent"] = function,
+ ["IgnoreAllEvents"] = function,
+ ["SetPoint"] = function,
+ ["GetPoint"] = function,
+ ["GetPointCount"] = function,
+ ["DelPoint"] = function,
+ ["SetAnchor"] = function,
+ ["GetAnchor"] = function,
+ ["GetAnchorCount"] = function,
+ ["ClearAnchors"] = function,
+ ["Show"] = function,
+ ["Hide"] = function,
+ ["DeleteFrame"] = function,
+ },
+ ...
+}
+
+LUA_REGISTRYINDEX =
+{
+ ["EVENT"] =
+ {
+ ["HANDLER"] =
+ {
+ [userdata] = function,
+ ...
+ },
+ [event name] =
+ {
+ [userdata] = true,
+ ...
+ },
+ ...
+ },
+ ["OBJECT"] =
+ {
+ [userdata] =
+ {
+ ["NAME"] = string,
+ ["POINT"] =
+ {
+ [0] = number, -- number of points the region has
+ [1, 2, 3, ...] =
+ {
+ ["NAME"] = string,
+ ["X"] = number,
+ ["Y"] = number,
+ ["ANCHORS"] = number, -- number of anchors set to this point; deletable only if equal to 0
+ },
+ [point name] = table, -- reverse lookup for points, used in L_GetPoint
+ },
+ ["ANCHOR"] =
+ {
+ [1, 2, 3, 4] =
+ {
+ ["SOURCE"] = string,
+ ["AXES"] = string,
+ ["X"] = number,
+ ["Y"] = number,
+ ["DEST_OBJECT"] = userdata,
+ ["DEST_POINT"] = string,
+ },
+ ["X1", "X2", "Y1", "Y2"] =
+ {
+ ["SOURCE"] = string,
+ ["OFFSET"] = number,
+ ["DEST_OBJECT"] = userdata,
+ ["DEST_POINT"] = string,
+ },
+ ["COMPLETE"] = boolean,
+ ["VALID"] = boolean,
+ },
+ ["EVENT"] =
+ {
+ [event name] = true,
+ ...
+ },
+ },
+ ...
+ [object name] = table, -- for looking up frames by name
+ ...
+ },
+}
+
+class Object_All
+{
+ public:
+ int depth, x, y, width, height;
+ bool visible;
+ protected:
+ private:
+};
+
+r:SetPoint("name", #x, #y) = nil
+r:DelPoint(#point) = nil
+r:GetPoint(#point) = "name", #x, #y, #anchors
+r:GetPointCount() = #points
+
+r:SetAnchor("source", destobj, "dest", "type", #off1[, #off2]) = nil
+r:ClearAnchors() = nil
+r:GetAnchor(#anchor) = "source", destobj, "dest", "type", #off1[, #off2]
+r:GetAnchorCount() = #anchors
11 RougeMUD-Client/doc/UI Mods.txt
@@ -0,0 +1,11 @@
+-mods are kept in one folder, and each is in its own folder inside there
+
+-RogueMUD -> Mods -> SomeMod
+ -> Some_Other Mod
+ -> A Different Mod
+
+The mod's folder contains all the files needed for the mod to run, which includes images, sound files, lua code files, and the mod definition file.
+
+MOD DEFINITION FILE
+-identified by having the same name as the mod's folder, with the file extension .mdf (eg. SomeMod.mdf)
+-
108 RougeMUD-Client/doc/UI Objects Overview.txt
@@ -0,0 +1,108 @@
+ USER INTERFACE OBJECTS OVERVIEW/CHEATSHEET
+TERMS:
+base object
+ -a UI object that is not createable by CreateFrame, but its methods are inherited through its derivatives
+complex object
+ -a UI object that is made up of multiple simple objects
+simple object
+ -a UI object that is a base type
+system object
+ -a UI object that is only created by developer code
+widget
+ -a component of the UI that the user can interact with, user made or developer made
+
+HEIRARCHY OF SIMPLE OBJECTS:
+Object* -> Frame -> Region -> Surface* -> Text -> FText???
+ -> Image
+ -> Secure* -> Button
+ -> Grip
+ -> WorldView*
+ -> GlobalRegion*
+*base/system object; uncreateable by CreateFrame
+
+DESCRIPTIONS OF SIMPLE OBJECTS:
+Button:
+ An object that can tell when it is clicked upon. Used in widgets that have mouse interaction.
+Frame:
+ A basic object, currently used for event interaction and as a base for event interaction, more to come...
+GlobalRegion:
+ A region, minus the ability to change its shape and position, that takes up the whole screen. Used as a base for anchoring objects, and is used to determine the position of every other region.
+Grip:
+ An object that can tell when it is dragged. Used in widgets that are to be dragged around or resized by the user.
+Image:
+ A high-use object that displays an image on the screen.
+Object:
+ Used as the base object for all interface objects.
+Region:
+ Used as the base object for all objects that have shape, visibility, position, and render priority. Also used as the parent for widgets, as an
+ invisible surface for controlling the shape and position of the entire widget.
+Secure:
+ Used as the base object for all objects that interact with the user. Blocks Lua access (via hooking) to certain functions at certain times, to
+ prevent cheating. The security of objects works upwards through descendance, so a secure object's descendants would not necessarily be secure, but
+ its ancestors always will be.
+Surface:
+ Used as the base object for all drawable objects.
+Text:
+ Another high-use object that displays a string of text on the screen.
+WorldView:
+ The main object of the game, displays the world as the character can see it. Is heavily hardcoded, and is a simple object from a UI perspective.
+ It is also a base object, making it uncreatable by CreateFrame. There is only one of it in the UI at any time, and the only interaction mods can
+ have on it are changing its dimensions. Otherwise, all of its work is accomplished through C++ code.
+
+not yet sorted...
+Font:
+ Holds settings for font implementation. Used by Text objects to control what font is used to render the text. Allows much more powerful control
+ over font usage, and provides methods to set font size, colour, justification, spacing, etc.
+
+METHODS AND TARGETTED EVENTS ADDED BY SIMPLE OBJECTS:
+Button:
+ events -
+ methods -
+Frame:
+ events -
+ methods -
+Image:
+ events -
+ methods -
+Object:
+ events - n/a
+ methods -
+Region:
+ events - n/a
+ methods - SetAnchor, SetAllAnchors, ClearAnchors, GetAnchor, GetAnchorCount, SetHeight, GetHeight, SetWidth, GetWidth
+Secure:
+ events -
+ methods -
+Surface:
+ events -
+ methods -
+Text:
+ events -
+ methods -
+note: only objects that derive from Frame have events, as Frame introduces event handling to the system
+
+DESCRIPTIONS OF COMPLEX OBJECTS:
+
+OVERVIEW OF OBJECT SECURITY:
+Object security is necessary for the environment, to prevent such cheating as making a mod that plays the game the player, to whatever extent. While all objects can be made secure, the main bulk of security is implemented in the Secure base object. The simple objects that inherit from the Secure object all interact directly with the user, such as clickable buttons.
+Security only kicks in during times when interface cheating would provide an unfair advantage, the primary example of which being combat. During a lockdown, which is declared by the C++ code, all objects that descend from Secure, and their ancenstors, lock themselves down to being programatically altered, moved, resized, etc. This makes it so that the only interaction with secure objects at this point is necessary use. Eg. the player can still drag around secure widgets themselves, and click buttons, but such actions as a mod loading keybindings from a stored profile are blocked.
+When secure objects are created and destroyed, the security status of their ancestors is re-evaluated. The security status of an object is stored in the C++ data, as an integer, with a value equal to the number of objects causing it to become secure, 0 meaning it is unsecure. So, when a secure object is created, all its ancestors have their security status value incremented once, and when a secure object is destroyed, its ancestors' security status value is decremented once. The calling or clearing of a lockdown causes all objects with a security status with a value over 0 to be locked down.
+There is also passive security built into the system, such as the architecture built up around the sending of commands. Secure commands, such as combat-related ones, can only be run through a button or keybinding, and the player must activate these. However, non-secure commands, such as whois requests and chat sends can be done automatically by mods.
+
+DESCRIPTIONS OF RENDERING LAYERS:
+LAYER_NORMAL:
+ Currently the only rendering layer.
+
+OVERVIEW OF RENDERING PROCESS:
+All objects of type Region, and its descendants, are placed in groups known as 'layers'. These layers are used during rendering to decide render priority. Layers that have a higher depth value are drawn sooner. Within a layer, the objects it includes also have a depth setting for inside that layer. This allows for easy grouping of similarily depthed objects, without needing a standard for which depth values to use.
+Not only are layers used for deciding the order in which to draw images to the screen, they are also used to decide which order elements should be checked in to see if they have been clicked upon. So if two clickable elements are on top of each other, and both cover the spot that was clicked, the one with less depth will be sent the event. However, if the top object receives click events, the bottom object receives drag events, and the user initiated a drag event, the bottom object will receive the event.
+
+OVERVIEW OF SHAPE AND ANCHOR POINTS OF REGION OBJECTS
+Another property of Region-type objects is that they have shape. This shape is defined in C++ with a simple x, y, width, height set of values, but in Lua, there is a much more in-depth set of variables to use, in the form of anchor points. Each region has nine anchor points (four corners, four edges, one center), as well as height and width values, that can all be set independently of each other. Width and height are simple numerical values, but anchor points are much more complex. They each hold an x and y offset value, as well as two values (point name and frame) used to point to the anchor point of any region that it will anchor to. This allows regions to be moved together easily and conveniently. Any frame with no anchors will treated as if its center is anchored to the center of the screen, using whatever offset it already had relative to the center.
+To control the anchor points, functions are available to region objects to set one anchor, delete one anchor, delete all anchors, or set all anchors to those of another object. When an anchor is set, what actually happens is based on what kind of anchor was set:
+Corner - anchors its two adjacent edges (overwrites adjacent corner anchors, and height+width+center anchors)
+Edge - the edge is anchored like normal (overwrites adjacent corner anchors, and height/width+center anchors)
+Center - all edges are anchored, using current height and width values for offset (overwrites all corner anchors)
+Height - changes top and bottom edge anchor offsets, based on which one was set more recently (more recent remains stationary, if set by a center anchor, they are moved equally) (this setting is like an anchor, in that it is persistant, until overwritten)
+Width - changes left and right edge anchor offsets, based on which one was set more recently (more recent remains stationary, if set by a center anchor, they are moved equally) (this setting is like an anchor, in that it is persistant, until overwritten)
+So in actuality, the only settings that matter are the edge anchors, width, and height values, as the corner and center anchors are simply there for convenience's sake. To send results through GetPoint(), a list is kept of the set anchor points, in the order that they were set. When some anchors are set, they delete other anchor entries in the list, as indicated above. If a point is set that is already in the list, the old entry is deleted. Height and width values are not on the list, instead when they are set they add edge anchors relative to the region's own center. This list is consulted when the C++ values for shape are determined.
14 RougeMUD-Client/doc/interface.txt
@@ -0,0 +1,14 @@
+-- INTERFACE
+UI made up of parts called objects.
+There are various types of objects; only textures are visible
+
+-- EVENTS
+UI functions by calling events, and objects handling them.
+Events are either called globally, over all objects, or is sent to one certain object
+
+-- global events
+UI_STEP
+UI_LOAD
+UI_QUIT
+
+-- targetted events
155 RougeMUD-Client/game.cpp
@@ -0,0 +1,155 @@
+#include "game.h"
+
+Game::Game()
+{
+ // Load images
+ string filename;
+ fstream fin("data/img.init", fstream::in);
+ while (!fin.eof())
+ {
+ getline(fin, filename);
+ vector<string> split;
+ //split the string into parts: name width height
+ StringExplode(filename.c_str(), " ", &split);
+ filename = split[0];
+
+ SDL_Surface *surface; // Gives us the information to make the texture
+ GLenum texture_format;
+ GLint nOfColors;
+ if ( (surface = SDL_LoadBMP(filename.c_str())) ) {
+ textureDB.push_back(*(new Texture));
+ // Check that the image's width is a power of 2
+ if ( (surface->w & (surface->w - 1)) != 0 ) {
+ printf("warning: image's width(%i) is not a power of 2\n", surface->w);
+ }
+
+ // Also check if the height is a power of 2
+ if ( (surface->h & (surface->h - 1)) != 0 ) {
+ printf("warning: image's height(%i) is not a power of 2\n", surface->h);
+ }
+
+ // get the number of channels in the SDL surface
+ nOfColors = surface->format->BytesPerPixel;
+ if (nOfColors == 4) // contains an alpha channel
+ {
+ if (surface->format->Rmask == 0x000000ff)
+ texture_format = GL_RGBA;
+ else
+ texture_format = GL_BGRA;
+ } else if (nOfColors == 3) // no alpha channel
+ {
+ if (surface->format->Rmask == 0x000000ff)
+ texture_format = GL_RGB;
+ else
+ texture_format = GL_BGR;
+ } else {
+ printf("warning: the image is not truecolor.. this will probably break\n");
+ // this error should not go unhandled
+ }
+
+ // Have OpenGL generate a texture object handle for us
+ glGenTextures( 1, &textureDB[textureDB.size()-1].texture );
+
+ // Bind the texture object
+ glBindTexture( GL_TEXTURE_2D, textureDB[textureDB.size()-1].texture );
+
+ // Set the texture's stretching properties
+ glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
+ glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
+
+ // Edit the texture object's image data using the information SDL_Surface gives us
+ glTexImage2D( GL_TEXTURE_2D, 0, nOfColors, surface->w, surface->h, 0, texture_format, GL_UNSIGNED_BYTE, surface->pixels );
+
+ //set dimensions for the loaded images
+ textureDB[textureDB.size()-1].origwidth = surface->w;
+ textureDB[textureDB.size()-1].origheight = surface->h;
+ textureDB[textureDB.size()-1].width = atoi(split[1].c_str());
+ textureDB[textureDB.size()-1].height = atoi(split[2].c_str());
+
+ }
+ else {
+ printf("SDL could not load image: %s\n", SDL_GetError());
+ SDL_Quit();
+ throw IMG_LOAD_EXCEPTION;
+ }
+
+
+ // Free the SDL_Surface only if it was successfully created
+ if ( surface ) {
+ SDL_FreeSurface( surface );
+ }
+ }
+
+ // Create the State objects, and make the Menu active
+ game_state = new State_Login();
+ cur_state = STATE_LOGIN;
+ next_state = STATE_NULL;
+}
+
+Game::~Game()
+{
+ // Free loaded bitmaps
+ for (unsigned int aa = 0; aa < textureDB.size(); aa++)
+ {
+ glDeleteTextures( 1, &textureDB[aa].texture );
+ }
+
+ printf("Exited cleanly\n");
+}
+
+void Game::LoopEvents()
+{
+ game_state->Event();
+}
+
+bool Game::LoopLogic()
+{
+ return game_state->Step();
+}
+
+bool Game::ChangeState()
+{
+ if (next_state != STATE_NULL)
+ {
+ if (next_state != STATE_EXIT)
+ {
+ delete game_state;
+ }
+ else
+ {
+ return true;
+ }
+
+ switch (next_state)
+ {
+ case STATE_LOGIN:
+ game_state = new State_Login();
+ break;
+ case STATE_GAME:
+ game_state = new State_Game();
+ break;
+ }
+
+ cur_state = next_state;
+ next_state = STATE_NULL;
+ }
+ return false;
+}
+
+void Game::LoopRender()
+{
+
+ // Draw from the state
+ glClear( GL_COLOR_BUFFER_BIT );
+
+ game_state->Draw();
+
+ glLoadIdentity();
+ SDL_GL_SwapBuffers();
+
+}
+
+const char* IMG_EXCEPTION::what() const throw()
+{
+ return "Image does not exist";
+}
52 RougeMUD-Client/game.h
@@ -0,0 +1,52 @@
+#ifndef ROGUEMUD_GAME_H
+#define ROGUEMUD_GAME_H
+
+#ifdef __cplusplus
+ #include <cstdlib>
+#else
+ #include <stdlib.h>
+#endif
+
+#include <SDL.h>
+#include <SDL_net.h>
+#include <SDL_opengl.h>
+
+#include <fstream>
+#include <string>
+#include <vector>
+
+#include "ns_game.h"
+#include "timer.h"
+#include "state.h"
+#include "state_game.h"
+#include "state_login.h"
+#include "texture.h"
+#include "being.h"
+
+using namespace std;
+using namespace ns_game;
+
+/**
+ The Game class encompasses the entire game, all other files are included from here
+**/
+
+class Game
+{
+ public:
+ Game();
+ ~Game();
+ void LoopEvents();
+ bool LoopLogic();
+ bool ChangeState();
+ void LoopRender();
+ protected:
+ private:
+ State* game_state;
+};
+
+class IMG_EXCEPTION: public exception
+{
+ virtual const char* what() const throw();
+}static IMG_LOAD_EXCEPTION;
+
+#endif
219 RougeMUD-Client/luaenv.cpp
@@ -0,0 +1,219 @@
+#include "luaenv.h"
+
+/// Creates and initializes a Lua environment
+void init_lua()
+{
+ // Create the Lua environment
+ LuaState = lua_open();
+ lua_State *L = LuaState;
+ luaL_openlibs(L);
+
+ // Register lua functions
+ lua_register(L, "Print", L_Print);
+ lua_register(L, "CreateFrame", L_CreateFrame);
+ lua_register(L, "GetRegistry", L_DebugRegTable);
+
+
+ // Create the event registry
+ lua_pushstring(L, "EVENT"); // +1 1
+ lua_newtable(L); // +1 2
+ // Put event tables into the event registry
+ // UI_STEP
+ lua_pushstring(L, "UI_STEP"); // +1 3
+ lua_newtable(L); // +1 4
+ lua_settable(L, -3); // -2 2
+ // UI_LOAD
+ lua_pushstring(L, "UI_LOAD"); // +1 3
+ lua_newtable(L); // +1 4
+ lua_settable(L, -3); // -2 2
+ // UI_QUIT
+ lua_pushstring(L, "UI_QUIT"); // +1 3
+ lua_newtable(L); // +1 4
+ lua_settable(L, -3); // -2 2
+ // Set the event registry table
+ lua_settable(L, LUA_REGISTRYINDEX); // -2 0
+
+ // Create the object registry
+ lua_newtable(L);
+ lua_setfield(L, LUA_REGISTRYINDEX, "OBJECT");
+
+ // Create the global region table
+ // new_table = {}
+ lua_newtable(L); // +1 1
+ int new_table = lua_gettop(L);
+ // PopulateTable(new_table)
+ Object_GlobalRegion *GlobalRegion = new Object_GlobalRegion(new_table);
+ lua_pop(L, lua_gettop(L)-new_table); // -? 1
+ // new_table[0] = *GlobalRegion
+ lua_pushnumber(L, 0); // +1 2
+ lua_pushlightuserdata(L, GlobalRegion); // +1 3
+ lua_settable(L, new_table); // -2 1
+ // _G.GlobalRegion = new_table
+ lua_setglobal(L, "GlobalRegion"); // -1 0
+}
+
+/// Cleans up the C++ objects made by the UI, and destroys the Lua environment
+void uninit_lua()
+{
+ lua_State *L = LuaState;
+
+ // Delete all C++ objects made by the UI
+ lua_getfield(L, LUA_REGISTRYINDEX, "OBJECT"); // +1 (1)
+ lua_pushnil(L); // +1 (2)
+ while (lua_next(L, -2) != 0) // +2, -1 (3)
+ {
+ // Get the pointer from 'k', and delete the object it points to
+ Object* object = (Object*)lua_touserdata(L, -2);
+ delete object;
+
+ // Pop 'v', leave 'k' for next iteration
+ lua_pop(L, 1); // -1 (2)
+ }
+
+ // Finally, close the Lua environment
+ lua_close(L);
+}
+
+/// Sends an event call to each listening frame that has a handler set up
+void SendEvent(const char* event)
+{
+ lua_State *L = LuaState;
+
+ // clear the stack
+ lua_settop(L, 0);
+
+ // Get the specified event table onto the stack
+ lua_getfield(L, LUA_REGISTRYINDEX, "EVENT"); // +1 1
+ lua_getfield(L, -1, event); // +1 2
+ int table_event = lua_gettop(L);
+
+ // Get the OBJECT table onto the stack
+ lua_getfield(L, LUA_REGISTRYINDEX, "OBJECT"); // +1 3
+ int reg_object = lua_gettop(L);
+
+ // Call the specified event function for each registered object
+ lua_pushnil(L); // +1 4
+ while (lua_next(L, table_event) != 0) // +2 -1 5
+ {
+ int k = lua_gettop(L)-1;
+
+ // Get the handler onto the stack
+ lua_pushvalue(L, -2); // +1 6
+ lua_gettable(L, reg_object); // +1 -1 6
+ lua_getfield(L, -1, "EVENT"); // +1 7
+ lua_getfield(L, -1, "HANDLER"); // +1 8
+ int func = lua_gettop(L);
+
+ // Push the arguments onto the stack
+ lua_pushstring(L, event); // +1 9
+
+ // Call the handler, if it is set
+ if(lua_isfunction(L, func)) lua_call(L, 1, 0); /// TODO: switch to pcall, and maybe organize this chunk better
+
+ // Remove added stack values, keep k for next iteration
+ lua_pop(L, lua_gettop(L)-k); // -? 4
+ }
+}
+
+/// Re-calculates the absolute position of the specified region and all those anchored to it
+/// Assumes the region(s) the specified region is anchored to already have accurate absolute positioning,
+/// if they have any, and [VALID] and [COMPLETED] are true
+/// Finding that [COMPLETED] is false is a dead end for resolving positions
+void ResolveRegionAbsolutePositions(Object_Region *object)
+{
+ lua_State *L = LuaState;
+
+ // Get the object's registry table
+ // t_object = LUA_REGISTRYINDEX.OBJECT[object]
+ lua_getfield(L, LUA_REGISTRYINDEX, "OBJECT");
+ lua_pushlightuserdata(L, object);
+ lua_gettable(L, -2);
+ int t_object = lua_gettop(L);
+
+ //
+}
+
+/// TODO: rework this to print to the chat output when they are implemented, instead of the debug window,
+/// which the release build does not include, or just use this as a debug function and remove it for the release build
+/// Lua function, prints out all values in the stack
+int L_Print(lua_State *L)
+{
+ // Print out all values on the stack
+ int top = lua_gettop(L);
+ for (int aa = 1; aa <= top; aa++)
+ {
+ if (lua_isstring(L, aa))
+ printf("%s", lua_tostring(L, aa));
+ else if (lua_isnil(L, aa))
+ printf("%s", "nil");
+ else if (lua_isboolean(L, aa))
+ printf("%s", lua_toboolean(L, aa) ? "true" : "false");
+ else
+ printf("%s:%p", luaL_typename(L, aa), lua_topointer(L, aa));
+ // End the line
+ printf("\n");
+ }
+
+ return 0;
+}
+
+/// Lua function, creates a new frame, made up of a C++ Object class, and a Lua table
+int L_CreateFrame(lua_State *L)
+{
+ // Create a lua table and give it a link to a new object of the specified type in key [0]
+
+ // Create a new table, and grab its position
+ lua_newtable(L); // +1 1
+ int new_table = lua_gettop(L);
+
+ // Fill in the table, by creating the appropriate kind, and then populating its table
+ /// TODO: sort the if-else chain by frequency use, in descending order, to optimize creation time, maybe rewrite to use radix tree to search
+
+ if (!strcmp(lua_tostring(L, 1), "frame"))
+ {
+ // old code, might need to revert to this if light userdata proves insufficient
+ //Object_ *object = (Object_*)lua_newuserdata(L, 8);
+ //object = new Object_(new_table);
+ Object_Frame *object = new Object_Frame(new_table);
+ lua_pushlightuserdata(L, object); // +1 2
+ }
+ else if (!strcmp(lua_tostring(L, 1), "region"))
+ {
+ Object_Region *object = new Object_Region(new_table);
+ lua_pushlightuserdata(L, object); // +1 2
+ }
+ else if (!strcmp(lua_tostring(L, 1), "text"))
+ {
+ Object_Text *object = new Object_Text(new_table);
+ lua_pushlightuserdata(L, object); // +1 2
+ }
+ else if (!strcmp(lua_tostring(L, 1), "image"))
+ {
+ Object_Image *object = new Object_Image(new_table);
+ lua_pushlightuserdata(L, object); // +1 2
+ }
+ else if (!strcmp(lua_tostring(L, 1), "button"))
+ {
+ Object_Button *object = new Object_Button(new_table);
+ lua_pushlightuserdata(L, object); // +1 3
+ }
+ else
+ {
+ lua_pushstring(L, "Error in function CreateFrame: parameter one has invalid value or type");
+ lua_error(L);
+ return 0;
+ }
+ lua_pushnumber(L, 0); // +1 4
+ lua_pushvalue(L, -2); // +1 5
+ lua_settable(L, new_table); // -2 3
+
+ lua_pushvalue(L, new_table);
+ return 1;
+}
+
+/// TODO: Remove this function before release!!! Don't forget to remove the pertinent lua_register() and .h prototype!
+int L_DebugRegTable(lua_State *L)
+{
+ lua_pushvalue(L, LUA_REGISTRYINDEX); // +1 1
+ return 1;
+}
31 RougeMUD-Client/luaenv.h
@@ -0,0 +1,31 @@
+#ifndef ROGUEMUD_LUAENV_H
+#define ROGUEMUD_LUAENV_H
+
+extern "C"
+{
+ #include <lua.h>
+ #include <lauxlib.h>
+ #include <lualib.h>
+}
+
+#include <vector>
+
+#include "ns_state_game.h"
+#include "object_button.h"
+#include "object_globalregion.h"
+#include "object_image.h"
+#include "object_text.h"
+#include "object_worldview.h"
+
+using namespace ns_state_game;
+
+void init_lua();
+void uninit_lua();
+void SendEvent(const char* event);
+void ResolveRegionAbsolutePositions(Object *object);
+
+int L_Print(lua_State *L);
+int L_CreateFrame(lua_State *L);
+int L_DebugRegTable(lua_State *L);
+
+#endif
154 RougeMUD-Client/main.cpp
@@ -0,0 +1,154 @@
+#include "game.h"
+#include "timer.h"
+
+#include "ns_game.h"
+
+using namespace ns_game;
+
+/**
+ The main function simply creates the Game object, and handles the game loop and fps
+**/
+
+bool init_net()
+{
+ // Initialize SDL_net
+ if (SDLNet_Init() < 0)
+ {
+ fprintf(stderr, "SDLNet_Init: %s\n", SDLNet_GetError());
+ return false;
+ }
+ // Open a socket on random port
+ if (!(sd = SDLNet_UDP_Open(3000)))
+ {
+ fprintf(stderr, "SDLNet_UDP_Open: %s\n", SDLNet_GetError());
+ return false;
+ }
+ // Resolve server name
+ if (SDLNet_ResolveHost(&srvadd, "127.0.0.1", atoi("2000")) == -1)
+ {
+ fprintf(stderr, "SDLNet_ResolveHost(%s %d): %s\n", "127.0.0.1", atoi("2000"), SDLNet_GetError());
+ return false;
+ }
+ // Allocate memory for the packet
+ if (!(p = SDLNet_AllocPacket(512)))
+ {
+ fprintf(stderr, "SDLNet_AllocPacket: %s\n", SDLNet_GetError());
+ return false;
+ }
+ p->address.host = srvadd.host; // Set the destination host
+ p->address.port = srvadd.port; // And destination port
+ return true;
+}
+
+bool init_GL()
+{
+ //Set clear color
+ glClearColor( 0, 0, 0, 0 );
+
+ glEnable( GL_TEXTURE_2D ); // Need this to display a texture
+
+ //Set projection
+ glMatrixMode( GL_PROJECTION );
+ glLoadIdentity();
+ glOrtho( 0, WIDTH, HEIGHT, 0, -1, 1 );
+
+ //Initialize modelview matrix
+ glMatrixMode( GL_MODELVIEW );
+ glLoadIdentity();
+
+ //If there was any errors
+ if( glGetError() != GL_NO_ERROR )
+ {
+ return false;
+ }
+
+ //If everything initialized
+ return true;
+}
+
+bool init()
+{
+ //Initialize SDL
+ if( SDL_Init( SDL_INIT_EVERYTHING ) < 0 )
+ {
+ return false;
+ }
+
+ SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
+
+ //Create Window
+ if( SDL_SetVideoMode( WIDTH, HEIGHT, 32, SDL_OPENGL/* | SDL_FULLSCREEN */) == NULL )
+ {
+ return false;
+ }
+
+ //Initialize OpenGL
+ if( init_GL() == false )
+ {
+ return false;
+ }
+
+ //Initialize SDL_net
+ if( init_net() == false )
+ {
+ return false;
+ }
+
+ //Set caption
+ SDL_WM_SetCaption( "RougeMUD", NULL );
+
+ return true;
+}
+
+int main (int argc, char** argv)
+{
+ WIDTH = 640;
+ HEIGHT = 480;
+
+ if( init() == false )
+ {
+ return 1;
+ }
+
+ // Engine vars
+ fps = 30;
+
+ // Initialize the game
+ Timer fpsTimer;
+ Game game;
+
+ try
+ {
+ // Call the game loop
+ for (;;)
+ {
+ fpsTimer.Start();
+
+ // Execute a frame's worth of activity
+ game.LoopEvents();
+ if (game.LoopLogic()) break;
+ if (game.ChangeState()) break;
+ game.LoopRender();
+
+ // Manage FPS
+ if (fpsTimer.GetTime() < 1000/fps)
+ {
+ SDL_Delay((1000/fps) - fpsTimer.GetTime());
+ }
+ cur_fps = 1000/fpsTimer.GetTime();
+ //printf("CurFPS: %i \n", cur_fps);
+ }
+
+ fpsTimer.Stop();
+ }
+ catch (exception& e)
+ {
+ printf("%s\n", e.what());
+ return 1;
+ }
+
+ SDL_FreeSurface(screen);
+
+ // Shut down the game
+ return 0;
+}
93 RougeMUD-Client/ns_game.cpp
@@ -0,0 +1,93 @@
+#include "ns_game.h"
+
+int ns_game::WIDTH, ns_game::HEIGHT, ns_game::fps, ns_game::cur_fps, ns_game::cur_state, ns_game::next_state, ns_game::ID;
+bool ns_game::FULLSCREEN;
+SDL_Surface* ns_game::screen;
+vector<Texture> ns_game::textureDB;
+vector<Being> ns_game::beingDB;
+SDL_Event ns_game::event;
+
+UDPsocket ns_game::sd;
+IPaddress ns_game::srvadd;
+UDPpacket *ns_game::p;
+
+string itoa (int n)
+{
+ char * s = new char[17];
+ string u;
+
+ if (n < 0) { //turns n positive
+ n = (-1 * n);
+ u = "-"; //adds '-' on result string
+ }
+
+ int i=0; //s counter
+
+ do {
+ s[i++]= n%10 + '0'; //conversion of each digit of n to char
+ n -= n%10; //update n value
+ }
+
+ while ((n /= 10) > 0);
+
+ for (int j = i-1; j >= 0; j--) {
+ u += s[j]; //building our string number
+ }
+
+ delete[] s; //free-up the memory!
+ return u;
+}
+// stolen function
+void StringExplode(string str, string separator, vector<string>* results)
+{
+ results->clear();
+ int found;
+ found = str.find_first_of(separator);
+ while(found != string::npos)
+ {
+ if(found > 0)
+ {
+ results->push_back(str.substr(0,found));
+ }
+ str = str.substr(found+1);
+ found = str.find_first_of(separator);
+ }
+ if(str.length() > 0)
+ {
+ results->push_back(str);
+ }
+}
+
+char* GetUDP()
+{
+ using namespace ns_game;
+
+ char* buf; // swap var
+ UDPpacket* pack = SDLNet_AllocPacket(512); // new packet
+ if(SDLNet_UDP_Recv(sd, pack)) // grab a packet if you can
+ {
+ // printf("UDP Packet incoming\n");
+ // printf("\tChan: %d\n", pack->channel);
+ // printf("\tData: %s\n", (char *)pack->data);
+ // printf("\tLen: %d\n", pack->len);
+ // printf("\tMaxlen: %d\n", pack->maxlen);
+ // printf("\tStatus: %d\n", pack->status);
+ // printf("\tAddress: %x %x\n", pack->address.host, pack->address.port);
+ buf = (char *)pack->data;
+ }
+ else // no packet to grab
+ {
+ buf = NULL;
+ }
+ SDLNet_FreePacket(pack);
+ return buf; // return packets data only
+}
+
+void SendUDP(const char* data)
+{
+ using namespace ns_game;
+
+ p->data = (Uint8 *)data;// sets packet data
+ p->len = strlen((char *)p->data) + 1;
+ SDLNet_UDP_Send(sd, -1, p);// sends packet
+}
47 RougeMUD-Client/ns_game.h
@@ -0,0 +1,47 @@
+#ifndef ROGUEMUD_NS_GAME_H
+#define ROGUEMUD_NS_GAME_H
+
+#include <SDL_net.h>
+#include <SDL_opengl.h>
+#include <vector>
+
+#include "texture.h"
+#include "being.h"
+
+class Game;
+class State;
+
+using namespace std;
+
+/**
+ The game namespace is used to statically store information introduced by game.h/cpp
+**/
+
+namespace ns_game
+{
+ extern int WIDTH, HEIGHT, fps, cur_fps, cur_state, next_state, ID;
+ extern bool FULLSCREEN;
+ extern SDL_Surface* screen;
+ extern vector<Texture> textureDB;
+ extern vector<Being> beingDB;
+ extern SDL_Event event;
+
+ extern UDPsocket sd;
+ extern IPaddress srvadd;
+ extern UDPpacket *p;
+
+ enum States
+ {
+ STATE_NULL,
+ STATE_LOGIN,
+ STATE_GAME,
+ STATE_EXIT,
+ };
+}
+
+string itoa (int n);
+void StringExplode(string str, string separator, vector<string>* results);
+char* GetUDP();
+void SendUDP(const char* data);
+
+#endif
5 RougeMUD-Client/ns_state_game.cpp
@@ -0,0 +1,5 @@
+#include "ns_state_game.h"
+
+lua_State *ns_state_game::LuaState;
+Object_Region *ns_state_game::region_global;
+vector<Object_Surface*> ns_state_game::obj_surfaceDB[1];
28 RougeMUD-Client/ns_state_game.h
@@ -0,0 +1,28 @@
+#ifndef ROGUEMUD_NS_STATE_GAME_H
+#define ROGUEMUD_NS_STATE_GAME_H
+
+#include <vector>
+
+class lua_State;
+class Object_Surface;
+class Object_Region;
+
+using namespace std;
+
+/**
+ The game namespace is used to statically store information introduced by state_game.h/cpp
+**/
+
+namespace ns_state_game
+{
+ extern lua_State *LuaState;
+ extern Object_Region *region_global;
+ extern vector<Object_Surface*> obj_surfaceDB[1];
+}
+
+// Definitions for referring to the layers by name in C++ code
+// Layers are drawn from lowest to highest, so this list will often be re-ordered
+// Preprocessor definitions are used to make the reordering simpler for us, with no runtime cost
+#define LAYER_NORMAL 0
+
+#endif
45 RougeMUD-Client/object.cpp
@@ -0,0 +1,45 @@
+#include "object.h"
+
+Object::Object()
+{
+}
+
+Object::Object(int new_table)
+{
+ PopulateTable(LuaState, new_table);
+ PopulateRegistry(LuaState);
+}
+
+Object::~Object()
+{
+}
+
+void Object::PopulateTable(lua_State *L, int new_table)
+{
+}
+
+void Object::PopulateRegistry(lua_State *L)
+{
+ // Create an entry in the Lua Registry for this new object
+ lua_getfield(L, LUA_REGISTRYINDEX, "OBJECT"); // +1 1
+ lua_pushlightuserdata(L, this); // +1 2
+ lua_newtable(L); // +1 3
+ lua_settable(L, -3); // -2 1
+ lua_pop(L, 1); // -1 0
+}
+
+/// Returns the pointer to the object specified by table or string reference
+int GetObject(int object)
+{
+ lua_State *L = LuaState;
+ /// TODO: make it also work by string reference
+
+ // Grab the object's pointer
+ if (lua_istable(L, 1))
+ {
+ lua_pushnumber(L, 0); // +1 1
+ lua_gettable(L, 1); // +1 2
+ return lua_gettop(L); // -2 0
+ }
+ return NULL;
+}
37 RougeMUD-Client/object.h
@@ -0,0 +1,37 @@
+#ifndef ROGUEMUD_OBJECT_H
+#define ROGUEMUD_OBJECT_H
+
+extern "C"
+{
+ #include <lua.h>
+}
+#include <SDL.h>
+
+#include "ns_state_game.h"
+
+using namespace ns_state_game;
+
+/**
+ The Object class is the parent of all interface objects. It is used only in State_Game, and plugs into the state's Lua functionality.
+ Some interface objects are hardcoded to prevent modification, such as the world view object (Object_World), or to provide basic functionality, such as
+ the texture object (Object_Texture).
+ Many interface objects, however, are coded in Lua, allowing free modification of them, such as the chat/command history view object,
+ or the F# paging bar object.
+**/
+
+class Object
+{
+ public:
+ Object();
+ Object(int new_table);
+ virtual ~Object();
+ virtual void PopulateTable(lua_State *L, int new_table);
+ virtual void PopulateRegistry(lua_State *L);
+ protected:
+ private:
+};
+
+int GetObject(int object);
+
+#endif
+
25 RougeMUD-Client/object_button.cpp
@@ -0,0 +1,25 @@
+#include "object_button.h"
+
+Object_Button::Object_Button()
+{
+}
+
+Object_Button::Object_Button(int new_table)
+{
+ PopulateTable(LuaState, new_table);
+ PopulateRegistry(LuaState);
+}
+
+Object_Button::~Object_Button()
+{
+}
+
+void Object_Button::PopulateTable(lua_State *L, int new_table)
+{
+ Object_Secure::PopulateTable(LuaState, new_table);
+}
+
+void Object_Button::PopulateRegistry(lua_State *L)
+{
+ Object_Secure::PopulateRegistry(LuaState);
+}
18 RougeMUD-Client/object_button.h
@@ -0,0 +1,18 @@
+#ifndef ROGUEMUD_OBJECT_BUTTON_H
+#define ROGUEMUD_OBJECT_BUTTON_H
+
+#include "object_secure.h"
+
+class Object_Button : public Object_Secure
+{
+ public:
+ Object_Button();
+ Object_Button(int new_table);
+ virtual ~Object_Button();
+ virtual void PopulateTable(lua_State *L, int new_table);
+ virtual void PopulateRegistry(lua_State *L);
+ protected:
+ private:
+};
+
+#endif
262 RougeMUD-Client/object_frame.cpp
@@ -0,0 +1,262 @@
+#include "object_frame.h"
+
+Object_Frame::Object_Frame()
+{
+}
+
+Object_Frame::Object_Frame(int new_table)
+{
+ PopulateTable(LuaState, new_table);
+ PopulateRegistry(LuaState);
+}
+
+Object_Frame::~Object_Frame()
+{
+}
+
+void Object_Frame::PopulateTable(lua_State *L, int new_table)
+{
+ Object::PopulateTable(LuaState, new_table);
+
+ // _G table
+ lua_pushstring(L, "SetEventHandler"); // +1 1
+ lua_pushcfunction(L, L_SetEventHandler); // +1 2
+ lua_settable(L, new_table); // -2 0
+ lua_pushstring(L, "NoticeEvent"); // +1 1
+ lua_pushcfunction(L, L_NoticeEvent); // +1 2
+ lua_settable(L, new_table); // -2 0
+ lua_pushstring(L, "NoticeAllEvents"); // +1 1
+ lua_pushcfunction(L, L_NoticeAllEvents); // +1 2
+ lua_settable(L, new_table); // -2 0
+ lua_pushstring(L, "IgnoreEvent"); // +1 1
+ lua_pushcfunction(L, L_IgnoreEvent); // +1 2
+ lua_settable(L, new_table); // -2 0
+ lua_pushstring(L, "IgnoreAllEvents"); // +1 1
+ lua_pushcfunction(L, L_IgnoreAllEvents); // +1 2
+ lua_settable(L, new_table); // -2 0
+}
+
+void Object_Frame::PopulateRegistry(lua_State *L)
+{
+ Object::PopulateRegistry(LuaState);
+
+ // Registry table
+ lua_getfield(L, LUA_REGISTRYINDEX, "OBJECT"); // +1 1
+ lua_pushlightuserdata(L, this); // +1 2
+ lua_gettable(L, -2); // +1 -1 2
+ int reg_table = lua_gettop(L);
+
+ // reg_table.EVENT = {}
+ lua_newtable(L); // +1 3
+ lua_setfield(L, reg_table, "EVENT"); // -2 1
+ lua_pop(L, 1); // -1 0
+}
+
+/// Lua function, sets the object to handle all events through the specified function
+/// Parameters are: (handler())
+/// handler() is the new function to use to handle events for this object
+int L_SetEventHandler(lua_State *L)
+{
+ // Grab the frame's pointer
+ int frame = GetObject(1);
+
+ // Get the object's events table on the stack
+ lua_getfield(L, LUA_REGISTRYINDEX, "OBJECT"); // +1 1
+ lua_pushvalue(L, frame); // +1 2
+ lua_gettable(L, -2); // +1 -1 2
+ lua_getfield(L, -1, "EVENT"); // +1 3
+
+ // Push the new handler onto the stack, then put it into the events table
+ lua_pushvalue(L, 2); // +1 4
+ lua_setfield(L, -2, "HANDLER"); // -1 3
+
+ return 0;
+}
+
+/// Lua function, registers the object to receive notification by the specified event(s)
+int L_NoticeEvent(lua_State *L)
+{
+ // Get the top of the arguments
+ int top = lua_gettop(L);
+
+ // Grab the frame's pointer
+ int frame = GetObject(1);
+
+ // Get the events registry table onto the stack
+ lua_getfield(L, LUA_REGISTRYINDEX, "EVENT"); // +1 1
+ int table_eventreg = lua_gettop(L);
+
+ // Get the object's event table onto the stack
+ lua_getfield(L, LUA_REGISTRYINDEX, "OBJECT"); // +1 2
+ lua_pushvalue(L, frame); // +1 3
+ lua_gettable(L, -2); // +1 -1 3
+ lua_getfield(L, -1, "EVENT"); // +1 4
+ int table_eventobj = lua_gettop(L);
+
+ // Notice all specified events in stack
+ for (int aa = 2; aa <= top; aa++)
+ {
+ if (lua_isstring(L, aa))
+ {
+ // Push the appropriate event table onto the stack
+ lua_pushvalue(L, aa); // +1 5
+ lua_gettable(L, table_eventreg); // +1 -1 5
+ int table_event = lua_gettop(L);
+ /// TODO: make it send an error if the event being registered does not exist, or is HANDLER
+
+ // Set event[frame] to true
+ lua_pushvalue(L, frame); // +1 6
+ lua_pushboolean(L, true); // +1 7
+ lua_settable(L, table_event); // -2 5
+
+ // Add the event to the object's list
+ lua_pushvalue(L, aa); // +1 6
+ lua_pushboolean(L, true); // +1 7
+ lua_settable(L, table_eventobj); // -2 5
+
+ lua_pop(L, 1); // -1 4
+ }
+ else
+ {
+ lua_pushstring(L, "Error in function NoticeEvent: parameter has invalid type");
+ lua_error(L);
+ }
+ }
+
+ return 0;
+}
+
+/// Lua function, registers the object to receive notification by all events
+int L_NoticeAllEvents(lua_State *L)
+{
+ // Grab the frame's pointer
+ int frame = GetObject(1);
+
+ // Push the events registry table onto the stack
+ lua_getfield(L, LUA_REGISTRYINDEX, "EVENT"); // +1 1
+ int table_eventreg = lua_gettop(L);
+
+ // Get the object's events table onto the stack
+ lua_getfield(L, LUA_REGISTRYINDEX, "OBJECT"); // +1 2
+ lua_pushvalue(L, frame); // +1 3
+ lua_gettable(L, -2); // +1 -1 3
+ lua_getfield(L, -1, "EVENT"); // +1 4
+ int table_eventobj = lua_gettop(L);
+
+ // Notice all events
+ lua_pushnil(L); // +1 5
+ while (lua_next(L, table_eventreg) != 0) // +2 -1 6
+ {
+ int string_event = lua_gettop(L)-1;
+ int table_event = lua_gettop(L);
+
+ // Set event[frame] to true
+ lua_pushvalue(L, frame); // +1 7
+ lua_pushboolean(L, true); // +1 8
+ lua_settable(L, table_event); // -2 6
+
+ // Add the event to the object's list
+ lua_pushvalue(L, string_event); // +1 7
+ lua_pushboolean(L, true); // +1 8
+ lua_settable(L, table_eventobj); // -2 6
+
+ // Removes v, k is kept for next iteration
+ lua_pop(L, 1); // -1 5
+ }
+
+ return 0;
+}
+
+/// Lua function, registers the object to no longer receive notification by the specified event(s)
+int L_IgnoreEvent(lua_State *L)
+{
+ // Get the top of the arguments
+ int top = lua_gettop(L);
+
+ // Grab the frame's pointer
+ int frame = GetObject(1);
+
+ // Get the events registry table onto the stack
+ lua_getfield(L, LUA_REGISTRYINDEX, "EVENT"); // +1 1
+ int table_eventreg = lua_gettop(L);
+
+ // Get the object's event table onto the stack
+ lua_getfield(L, LUA_REGISTRYINDEX, "OBJECT"); // +1 2
+ lua_pushvalue(L, frame); // +1 3
+ lua_gettable(L, -2); // +1 -1 3
+ lua_getfield(L, -1, "EVENT"); // +1 4
+ int table_eventobj = lua_gettop(L);
+
+ // Ignore all specified events in stack
+ for (int aa = 2; aa <= top; aa++)
+ {
+ if (lua_isstring(L, aa))
+ {
+ // Push the appropriate event table onto the stack
+ lua_pushvalue(L, aa); // +1 5
+ lua_gettable(L, table_eventreg); // +1 -1 5
+ int table_event = lua_gettop(L);
+ /// TODO: make it send an error if the event being unregistered does not exist, or is HANDLER
+
+ // Set table[frame] to nil
+ lua_pushvalue(L, frame); // +1 6
+ lua_pushnil(L); // +1 7
+ lua_settable(L, table_event); // -2 5
+
+ // Remove the event from the object's list
+ lua_pushvalue(L, aa); // +1 6
+ lua_pushnil(L); // +1 7
+ lua_settable(L, table_eventobj); // -2 5
+
+ lua_pop(L, 1); // -1 4
+ }
+ else
+ {
+ lua_pushstring(L, "Error in function Event: parameter has invalid type");
+ lua_error(L);
+ }
+ }
+
+ return 0;
+}
+
+/// Lua function, registers the object to no longer receive notification by all events
+int L_IgnoreAllEvents(lua_State *L)
+{
+ // Grab the frame's pointer
+ int frame = GetObject(1);
+
+ // Push the events registry table onto the stack
+ lua_getfield(L, LUA_REGISTRYINDEX, "EVENT"); // +1 1
+ int table_eventreg = lua_gettop(L);
+
+ // Get the object's events table onto the stack
+ lua_getfield(L, LUA_REGISTRYINDEX, "OBJECT"); // +1 2
+ lua_pushvalue(L, frame); // +1 3
+ lua_gettable(L, -2); // +1 -1 3
+ lua_getfield(L, -1, "EVENT"); // +1 4
+ int table_eventobj = lua_gettop(L);
+
+ // Ignore all events
+ lua_pushnil(L); // +1 5
+ while (lua_next(L, table_eventreg) != 0) // +2 -1 6
+ {
+ int string_event = lua_gettop(L)-1;
+ int table_event = lua_gettop(L);
+
+ // Set event[frame] to nil
+ lua_pushvalue(L, frame); // +1 7
+ lua_pushnil(L); // +1 8
+ lua_settable(L, table_event); // -2 6
+
+ // Remove the event from the object's list
+ lua_pushvalue(L, string_event); // +1 7
+ lua_pushnil(L); // +1 8
+ lua_settable(L, table_eventobj); // -2 6
+
+ // Removes v, k is kept for next iteration
+ lua_pop(L, 1); // -1 5
+ }
+
+ return 0;
+}
24 RougeMUD-Client/object_frame.h
@@ -0,0 +1,24 @@
+#ifndef ROGUEMUD_OBJECT_FRAME_H
+#define ROGUEMUD_OBJECT_FRAME_H
+
+#include "object.h"
+
+class Object_Frame : public Object
+{
+ public:
+ Object_Frame();
+ Object_Frame(int new_table);
+ virtual~Object_Frame();
+ void PopulateTable(lua_State *L, int new_table);
+ virtual void PopulateRegistry(lua_State *L);
+ protected:
+ private:
+};
+
+int L_SetEventHandler(lua_State *L);
+int L_NoticeEvent(lua_State *L);
+int L_NoticeAllEvents(lua_State *L);
+int L_IgnoreEvent(lua_State *L);
+int L_IgnoreAllEvents(lua_State *L);
+
+#endif
124 RougeMUD-Client/object_globalregion.cpp
@@ -0,0 +1,124 @@
+#include "object_globalregion.h"
+
+Object_GlobalRegion::Object_GlobalRegion()
+{
+ x = 0;
+ y = 0;
+ width = WIDTH;
+ height = HEIGHT;
+}
+
+Object_GlobalRegion::Object_GlobalRegion(int new_table)
+{
+ PopulateTable(LuaState, new_table);
+ PopulateRegistry(LuaState);
+}
+
+Object_GlobalRegion::~Object_GlobalRegion()
+{
+}
+
+void Object_GlobalRegion::PopulateTable(lua_State *L, int new_table)
+{
+ lua_pushstring(L, "Show"); // +1 1
+ lua_pushcfunction(L, L_Show); // +1 2
+ lua_settable(L, new_table); // -2 0
+ lua_pushstring(L, "Hide"); // +1 1
+ lua_pushcfunction(L, L_Hide); // +1 2
+ lua_settable(L, new_table); // -2 0
+/* lua_pushstring(L, "SetPoint"); // +1 1
+ lua_pushcfunction(L, L_SetPoint); // +1 2
+ lua_settable(L, new_table); // -2 0
+ lua_pushstring(L, "DelPoint"); // +1 1
+ lua_pushcfunction(L, L_GetPoint); // +1 2
+ lua_settable(L, new_table); // -2 0
+ lua_pushstring(L, "GetPoint"); // +1 1
+ lua_pushcfunction(L, L_GetPoint); // +1 2
+ lua_settable(L, new_table); // -2 0
+ lua_pushstring(L, "GetPointCount"); // +1 1
+ lua_pushcfunction(L, L_GetPointCount); // +1 2
+ lua_settable(L, new_table); // -2 0*/
+}
+
+void Object_GlobalRegion::PopulateRegistry(lua_State *L)
+{
+ Object::PopulateRegistry(L);
+
+/* int top = lua_gettop(L);
+
+ // Registry table
+ lua_getfield(L, LUA_REGISTRYINDEX, "OBJECT"); // +1 1
+ lua_pushlightuserdata(L, this); // +1 2
+ lua_gettable(L, -2); // +1 -1 2
+ int reg_table = lua_gettop(L);
+ // Point table
+ lua_pushstring(L, "POINT"); // +1 4
+ lua_newtable(L); // +1 5
+ // Point count field
+ lua_pushnumber(L, 0); // +1 6
+ lua_pushnumber(L, 5); // +1 7
+ lua_settable(L, -3); // -2 5
+ // TOP LEFT point
+ lua_pushnumber(L, 1); // +1 6
+ lua_newtable(L); // +1 7
+ lua_pushstring(L, "TOPLEFT"); // +1 8
+ lua_setfield(L, -2, "NAME"); // -1 7
+ lua_pushnumber(L, 0); // +1 8
+ lua_setfield(L, -2, "X"); // -1 7
+ lua_pushnumber(L, 0); // +1 8
+ lua_setfield(L, -2, "Y"); // -1 7
+ lua_pushnumber(L, 0); // +1 8
+ lua_setfield(L, -2, "ANCHORS"); // -1 7
+ lua_settable(L, -3); // -2 5
+ // TOP RIGHT point
+ lua_pushnumber(L, 2); // +1 6
+ lua_newtable(L); // +1 7
+ lua_pushstring(L, "TOPRIGHT"); // +1 8
+ lua_setfield(L, -2, "NAME"); // -1 7
+ lua_pushnumber(L, 1); // +1 8
+ lua_setfield(L, -2, "X"); // -1 7
+ lua_pushnumber(L, 0); // +1 8
+ lua_setfield(L, -2, "Y"); // -1 7
+ lua_pushnumber(L, 0); // +1 8
+ lua_setfield(L, -2, "ANCHORS"); // -1 7
+ lua_settable(L, -3); // -2 5
+ // BOTTOM LEFT point
+ lua_pushnumber(L, 3); // +1 6
+ lua_newtable(L); // +1 7
+ lua_pushstring(L, "BOTTOMLEFT"); // +1 8
+ lua_setfield(L, -2, "NAME"); // -1 7
+ lua_pushnumber(L, 0); // +1 8
+ lua_setfield(L, -2, "X"); // -1 7
+ lua_pushnumber(L, 1); // +1 8
+ lua_setfield(L, -2, "Y"); // -1 7
+ lua_pushnumber(L, 0); // +1 8
+ lua_setfield(L, -2, "ANCHORS"); // -1 7
+ lua_settable(L, -3); // -2 5
+ // BOTTOM RIGHT point
+ lua_pushnumber(L, 4); // +1 6
+ lua_newtable(L); // +1 7
+ lua_pushstring(L, "BOTTOMRIGHT"); // +1 8
+ lua_setfield(L, -2, "NAME"); // -1 7
+ lua_pushnumber(L, 1); // +1 8
+ lua_setfield(L, -2, "X"); // -1 7
+ lua_pushnumber(L, 1); // +1 8
+ lua_setfield(L, -2, "Y"); // -1 7
+ lua_pushnumber(L, 0); // +1 8
+ lua_setfield(L, -2, "ANCHORS"); // -1 7
+ lua_settable(L, -3); // -2 5
+ // CENTER point
+ lua_pushnumber(L, 5); // +1 6
+ lua_newtable(L); // +1 7
+ lua_pushstring(L, "CENTER"); // +1 8
+ lua_setfield(L, -2, "NAME"); // -1 7
+ lua_pushnumber(L, 0.5); // +1 8
+ lua_setfield(L, -2, "X"); // -1 7
+ lua_pushnumber(L, 0.5); // +1 8
+ lua_setfield(L, -2, "Y"); // -1 7
+ lua_pushnumber(L, 0); // +1 8
+ lua_setfield(L, -2, "ANCHORS"); // -1 7
+ lua_settable(L, -3); // -2 5
+ lua_settable(L, reg_table); // -2 3
+
+ lua_pop(L, lua_gettop(L)-top);*/
+}
22 RougeMUD-Client/object_globalregion.h
@@ -0,0 +1,22 @@
+#ifndef ROGUEMUD_OBJECT_GLOBALREGION_H
+#define ROGUEMUD_OBJECT_GLOBALREGION_H
+
+#include "ns_game.h"
+#include "object_region.h"
+
+using namespace ns_game;
+
+class Object_GlobalRegion : public Object_Region
+{
+ public:
+ Object_GlobalRegion();
+ Object_GlobalRegion(int new_table);
+ virtual ~Object_GlobalRegion();
+
+ virtual void PopulateTable(lua_State *L, int new_table);
+ virtual void PopulateRegistry(lua_State *L);
+ protected:
+ private:
+};
+
+#endif
30 RougeMUD-Client/object_image.cpp
@@ -0,0 +1,30 @@
+#include "object_image.h"
+
+Object_Image::Object_Image()
+{
+}
+
+Object_Image::Object_Image(int new_table)
+{
+ PopulateTable(LuaState, new_table);
+ PopulateRegistry(LuaState);
+}
+
+Object_Image::~Object_Image()
+{
+}
+
+void Object_Image::PopulateTable(lua_State *L, int new_table)
+{
+ Object_Surface::PopulateTable(LuaState, new_table);
+}
+
+void Object_Image::PopulateRegistry(lua_State *L)
+{
+ Object_Surface::PopulateRegistry(LuaState);
+}
+
+void Object_Image::Draw()
+{
+
+}
19 RougeMUD-Client/object_image.h
@@ -0,0 +1,19 @@
+#ifndef ROGUEMUD_OBJECT_IMAGE_H
+#define ROGUEMUD_OBJECT_IMAGE_H
+
+#include "object_surface.h"
+
+class Object_Image : public Object_Surface
+{
+ public:
+ Object_Image();
+ Object_Image(int new_table);
+ virtual ~Object_Image();
+ virtual void PopulateTable(lua_State *L, int new_table);
+ virtual void PopulateRegistry(lua_State *L);
+ virtual void Draw();
+ protected:
+ private:
+};
+
+#endif
765 RougeMUD-Client/object_region.cpp
@@ -0,0 +1,765 @@
+#include "object_region.h"
+
+Object_Region::Object_Region()
+{
+ x = 0;
+ y = 0;
+ width = 0;
+ height = 0;
+ depth = 0;
+ visible = true;
+}
+
+Object_Region::Object_Region(int new_table)
+{
+ x = 0;
+ y = 0;
+ width = 0;
+ height = 0;
+ depth = 0;
+ visible = true;
+ PopulateTable(LuaState, new_table);
+ PopulateRegistry(LuaState);
+}
+
+Object_Region::~Object_Region()
+{
+}
+
+void Object_Region::PopulateTable(lua_State *L, int new_table)
+{
+ Object_Frame::PopulateTable(LuaState, new_table);
+
+ // _G table
+ lua_pushstring(L, "Show"); // +1 1
+ lua_pushcfunction(L, L_Show); // +1 2
+ lua_settable(L, new_table); // -2 0
+ lua_pushstring(L, "Hide"); // +1 1
+ lua_pushcfunction(L, L_Hide); // +1 2
+ lua_settable(L, new_table); // -2 0
+ lua_pushstring(L, "GetX"); // +1 1
+ lua_pushcfunction(L, L_GetX); // +1 2
+ lua_settable(L, new_table); // -2 0
+ lua_pushstring(L, "GetY"); // +1 1
+ lua_pushcfunction(L, L_GetY); // +1 2
+ lua_settable(L, new_table); // -2 0
+ lua_pushstring(L, "GetW"); // +1 1
+ lua_pushcfunction(L, L_GetW); // +1 2
+ lua_settable(L, new_table); // -2 0
+ lua_pushstring(L, "GetH"); // +1 1
+ lua_pushcfunction(L, L_GetH); // +1 2
+ lua_settable(L, new_table); // -2 0
+ lua_pushstring(L, "SetX"); // +1 1
+ lua_pushcfunction(L, L_SetX); // +1 2
+ lua_settable(L, new_table); // -2 0
+ lua_pushstring(L, "SetY"); // +1 1
+ lua_pushcfunction(L, L_SetY); // +1 2
+ lua_settable(L, new_table); // -2 0
+ lua_pushstring(L, "SetW"); // +1 1
+ lua_pushcfunction(L, L_SetW); // +1 2
+ lua_settable(L, new_table); // -2 0
+ lua_pushstring(L, "SetH"); // +1 1
+ lua_pushcfunction(L, L_SetH); // +1 2
+ lua_settable(L, new_table); // -2 0
+/* lua_pushstring(L, "SetPoint"); // +1 1
+ lua_pushcfunction(L, L_SetPoint); // +1 2
+ lua_settable(L, new_table); // -2 0
+ lua_pushstring(L, "DelPoint"); // +1 1
+ lua_pushcfunction(L, L_DelPoint); // +1 2
+ lua_settable(L, new_table); // -2 0
+ lua_pushstring(L, "GetPoint"); // +1 1
+ lua_pushcfunction(L, L_GetPoint); // +1 2
+ lua_settable(L, new_table); // -2 0
+ lua_pushstring(L, "GetPointCount"); // +1 1
+ lua_pushcfunction(L, L_GetPointCount); // +1 2
+ lua_settable(L, new_table); // -2 0
+ lua_pushstring(L, "SetAnchor"); // +1 1
+ lua_pushcfunction(L, L_SetAnchor); // +1 2
+ lua_settable(L, new_table); // -2 0
+ lua_pushstring(L, "SetAnchor"); // +1 1
+ lua_pushcfunction(L, L_SetAnchor); // +1 2
+ lua_settable(L, new_table); // -2 0
+ lua_pushstring(L, "GetAnchor"); // +1 1
+ lua_pushcfunction(L, L_GetAnchor); // +1 2
+ lua_settable(L, new_table); // -2 0
+ lua_pushstring(L, "GetAnchorCount"); // +1 1
+ lua_pushcfunction(L, L_GetAnchorCount); // +1 2
+ lua_settable(L, new_table); // -2 0
+ lua_pushstring(L, "ClearAnchors"); // +1 1
+ lua_pushcfunction(L, L_ClearAnchors); // +1 2
+ lua_settable(L, new_table); // -2 0*/
+}
+
+void Object_Region::PopulateRegistry(lua_State *L)
+{
+ Object_Frame::PopulateRegistry(LuaState);
+
+ int top = lua_gettop(L);
+
+/* // Registry table
+ lua_getfield(L, LUA_REGISTRYINDEX, "OBJECT"); // +1 1
+ lua_pushlightuserdata(L, this); // +1 2
+ lua_gettable(L, -2); // +1 -1 2
+ int reg_table = lua_gettop(L);
+ // Point table
+ lua_pushstring(L, "POINT"); // +1 4
+ lua_newtable(L); // +1 5
+ // Point count field
+ lua_pushnumber(L, 0); // +1 6
+ lua_pushnumber(L, 5); // +1 7
+ lua_settable(L, -3); // -2 5
+ // TOP LEFT point
+ lua_pushnumber(L, 1); // +1 6
+ lua_newtable(L); // +1 7
+ lua_pushstring(L, "TOPLEFT"); // +1 8
+ lua_setfield(L, -2, "NAME"); // -1 7
+ lua_pushnumber(L, 0); // +1 8
+ lua_setfield(L, -2, "X"); // -1 7
+ lua_pushnumber(L, 0); // +1 8
+ lua_setfield(L, -2, "Y"); // -1 7
+ lua_pushnumber(L, 0); // +1 8
+ lua_setfield(L, -2, "ANCHORS"); // -1 7
+ lua_settable(L, -3); // -2 5
+ // TOP RIGHT point
+ lua_pushnumber(L, 2); // +1 6
+ lua_newtable(L); // +1 7
+ lua_pushstring(L, "TOPRIGHT"); // +1 8
+ lua_setfield(L, -2, "NAME"); // -1 7
+ lua_pushnumber(L, 1); // +1 8
+ lua_setfield(L, -2, "X"); // -1 7
+ lua_pushnumber(L, 0); // +1 8
+ lua_setfield(L, -2, "Y"); // -1 7
+ lua_pushnumber(L, 0); // +1 8
+ lua_setfield(L, -2, "ANCHORS"); // -1 7
+ lua_settable(L, -3); // -2 5
+ // BOTTOM LEFT point
+ lua_pushnumber(L, 3); // +1 6
+ lua_newtable(L); // +1 7
+ lua_pushstring(L, "BOTTOMLEFT"); // +1 8
+ lua_setfield(L, -2, "NAME"); // -1 7
+ lua_pushnumber(L, 0); // +1 8
+ lua_setfield(L, -2, "X"); // -1 7
+ lua_pushnumber(L, 1); // +1 8
+ lua_setfield(L, -2, "Y"); // -1 7
+ lua_pushnumber(L, 0); // +1 8
+ lua_setfield(L, -2, "ANCHORS"); // -1 7
+ lua_settable(L, -3); // -2 5
+ // BOTTOM RIGHT point
+ lua_pushnumber(L, 4); // +1 6
+ lua_newtable(L); // +1 7
+ lua_pushstring(L, "BOTTOMRIGHT"); // +1 8
+ lua_setfield(L, -2, "NAME"); // -1 7
+ lua_pushnumber(L, 1); // +1 8
+ lua_setfield(L, -2, "X"); // -1 7
+ lua_pushnumber(L, 1); // +1 8
+ lua_setfield(L, -2, "Y"); // -1 7
+ lua_pushnumber(L, 0); // +1 8
+ lua_setfield(L, -2, "ANCHORS"); // -1 7
+ lua_settable(L, -3); // -2 5
+ // CENTER point
+ lua_pushnumber(L, 5); // +1 6
+ lua_newtable(L); // +1 7
+ lua_pushstring(L, "CENTER"); // +1 8
+ lua_setfield(L, -2, "NAME"); // -1 7
+ lua_pushnumber(L, 0.5); // +1 8
+ lua_setfield(L, -2, "X"); // -1 7
+ lua_pushnumber(L, 0.5); // +1 8
+ lua_setfield(L, -2, "Y"); // -1 7
+ lua_pushnumber(L, 0); // +1 8
+ lua_setfield(L, -2, "ANCHORS"); // -1 7
+ lua_settable(L, -3); // -2 5
+ lua_settable(L, reg_table); // -2 3
+
+ // Anchor table
+ // t_new = {}
+ lua_pushstring(L, "ANCHOR"); // +1 4
+ lua_newtable(L); // +1 5
+ int t_new = lua_gettop(L);
+ // Anchor count field
+ lua_pushnumber(L, 0); // +1 6
+ lua_pushnumber(L, 0); // +1 7
+ lua_settable(L, t_new); // -2 5
+ // t_new.COMPLETED = false
+ lua_pushboolean(L, false); // +1 6
+ lua_setfield(L, t_new, "COMPLETED"); // -1 5
+ // t_new.VALID = false
+ lua_pushboolean(L, false); // +1 6
+ lua_setfield(L, t_new, "VALID"); // -1 5
+ // reg_table.ANCHOR = t_new
+ lua_settable(L, reg_table); // -2 3*/
+
+ lua_pop(L, lua_gettop(L)-top);
+}
+
+/// Lua function, sets the region's render status to true
+int L_Show(lua_State *L)
+{
+ // Grab the frame's pointer
+ int frame = GetObject(1);
+
+ // Make the region visible
+ ((Object_Region*)lua_touserdata(L, frame))->visible = true;
+ return 0;
+}
+
+/// Lua function, sets the region's render status to false
+int L_Hide(lua_State *L)
+{
+ // Grab the frame's pointer
+ int frame = GetObject(1);
+
+ // Make the region invisible
+ ((Object_Region*)lua_touserdata(L, frame))->visible = false;
+ return 0;
+}
+
+int L_GetX(lua_State *L)
+{
+ int frame = GetObject(1);
+
+ Object_Region *object = (Object_Region*)lua_topointer(L, frame);
+
+ lua_pushnumber(L, object->x);
+
+ return 1;
+}
+
+int L_SetX(lua_State *L)
+{
+ int frame = GetObject(1);
+
+ Object_Region *object = (Object_Region*)lua_topointer(L, frame);
+
+ object->x = lua_tonumber(L, 2);
+
+ return 0;
+}
+
+int L_GetY(lua_State *L)
+{
+ int frame = GetObject(1);
+
+ Object_Region *object = (Object_Region*)lua_topointer(L, frame);
+
+ lua_pushnumber(L, object->y);
+
+ return 1;
+}
+
+int L_SetY(lua_State *L)
+{
+ int frame = GetObject(1);
+
+ Object_Region *object = (Object_Region*)lua_topointer(L, frame);
+
+ object->y = lua_tonumber(L, 2);
+
+ return 0;
+}
+
+int L_GetH(lua_State *L)
+{
+ int frame = GetObject(1);
+
+ Object_Region *object = (Object_Region*)lua_topointer(L, frame);
+
+ lua_pushnumber(L, object->height);
+
+ return 1;
+}
+
+int L_SetH(lua_State *L)
+{
+ int frame = GetObject(1);
+
+ Object_Region *object = (Object_Region*)lua_topointer(L, frame);
+
+ object->height = lua_tonumber(L, 2);
+
+ return 0;
+}
+
+int L_GetW(lua_State *L)
+{
+ int frame = GetObject(1);
+
+ Object_Region *object = (Object_Region*)lua_topointer(L, frame);
+
+ lua_pushnumber(L, object->width);
+
+ return 1;
+}
+
+int L_SetW(lua_State *L)
+{
+ int frame = GetObject(1);
+
+ Object_Region *object = (Object_Region*)lua_topointer(L, frame);
+
+ object->width = lua_tonumber(L, 2);
+
+ return 0;
+}
+
+
+/*/// Lua function, sets the values of the specified custom point, making a new one if necessary
+/// Parameters are: ("point", #x, #y)
+/// "point" is the name of the point, #x/#y, when multiplied by width/height, are the x/y offsets from the top left corner of the region
+int L_SetPoint(lua_State *L)
+{
+ /// TODO: add checks to prevent overwriting of preset points
+ /// TODO: make it add a second link with a numerical index to the added table
+
+ // Grab the frame's pointer
+ int frame = GetObject(1);
+
+ // Get the object's point table on the stack
+ // local t_point = LUA_REGISTRYINDEX.OBJECT[frame].POINT
+ lua_getfield(L, LUA_REGISTRYINDEX, "OBJECT"); // +1 1
+ lua_pushvalue(L, frame); // +1 2
+ lua_gettable(L, -2); // +1 -1 2
+ lua_getfield(L, -1, "POINT"); // +1 3
+ int t_point = lua_gettop(L);
+
+ // Add a new point, with the specified name
+ // local t_newpoint = {}
+ lua_pushvalue(L, 2); // +1 4
+ lua_newtable(L); // +1 5
+ int t_newpoint = lua_gettop(L);
+ // t_newpoint.NAME = name
+ lua_pushvalue(L, 2); // +1 6
+ lua_setfield(L, t_newpoint, "NAME"); // -1 5
+ // t_newpoint.X = new_x
+ lua_pushvalue(L, 3); // +1 6
+ lua_setfield(L, t_newpoint, "X"); // -1 5
+ // t_newpoint.Y = new_y
+ lua_pushvalue(L, 4); // +1 6
+ lua_setfield(L, t_newpoint, "Y"); // -1 5
+ // t_point[name] = t_newpoint
+ lua_settable(L, t_point); // -2 3
+
+ // Increment the value of [0] by one
+ // local num = t_newpoint[0]
+ lua_pushnumber(L, 0); // +1 4
+ lua_gettable(L, t_newpoint); // +1 -1 4
+ lua_Number num = lua_tonumber(L, -1);
+ // t_newpoint[0] = num+1
+ lua_pushnumber(L, 0); // +1 5
+ lua_pushnumber(L, num+1); // +1 6
+ lua_settable(L, t_newpoint); // -2 4
+
+ return 0;
+}
+
+/// Lua function, deletes the specified point on the region
+/// Parameters are: ("point")
+/// "point" is the name of the point to delete
+int L_DelPoint(lua_State *L)
+{
+ /// TODO: make it shift the larger indexes back down to fill the gap left
+ /// TODO: make it also able to delete points by numerical index
+ // Grab the frame's pointer
+ int frame = GetObject(1);
+
+ // Get the object's point table on the stack
+ // local t_point = LUA_REGISTRYINDEX.OBJECT[frame].POINT
+ lua_getfield(L, LUA_REGISTRYINDEX, "OBJECT"); // +1 1
+ lua_pushvalue(L, frame); // +1 2
+ lua_gettable(L, -2); // +1 -1 2
+ lua_getfield(L, -1, "POINT"); // +1 3
+ int t_point = lua_gettop(L);
+
+ // Check if the point exists
+ // if (type(t_point[name]) == 'table') then
+ lua_pushvalue(L, 2); // +1 4
+ lua_gettable(L, t_point); // +1 -1 4
+ if (lua_istable(L, -1))
+ {
+ // Delete the point
+ // t_point[name] = nil
+ lua_pushvalue(L, 2); // +1 5
+ lua_pushnil(L); // +1 6
+ lua_settable(L, t_point); // -2 4
+
+ // Decrement the value of [0] by one
+ // num = t_point[0]
+ lua_pushnumber(L, 0); // +1 5
+ lua_gettable(L, t_point); // +1 -1 5
+ lua_Number num = lua_tonumber(L, -1);
+ // t_point[0] = num+1
+ lua_pushnumber(L, 0); // +1 6
+ lua_pushnumber(L, num-1); // +1 7
+ lua_settable(L, t_point); // -2 5
+ }
+
+ return 0;
+}
+
+/// Lua function, returns the information on the specified point, by number or by
+int L_GetPoint(lua_State *L)
+{
+ // Grab the frame's pointer
+ int frame = GetObject(1);
+
+ // Get the object's point table
+ // local t_point = LUA_REGISTRYINDEX.OBJECT[frame].POINT
+ lua_getfield(L, LUA_REGISTRYINDEX, "OBJECT"); // +1 1
+ lua_pushvalue(L, frame); // +1 2
+ lua_gettable(L, -2); // +1 -1 2
+ lua_getfield(L, -1, "POINT"); // +1 3
+ int t_point = lua_gettop(L);
+
+ // Get the table of the specified point
+ /// TODO: add checks to see that the specified point exists, and is not index [0]
+
+ // Get the values from the point onto the stack and return them
+ // return t_point.NAME, t_point.X, t_point.Y, t_point.ANCHORS
+ lua_getfield(L, t_point, "NAME"); // +1 4
+ lua_getfield(L, t_point, "X"); // +1 5
+ lua_getfield(L, t_point, "Y"); // +1 6
+ lua_getfield(L, t_point, "ANCHORS"); // +1 7
+
+ return 4;
+}
+
+/// Lua function, returns the number of points on the region
+int L_GetPointCount(lua_State *L)
+{
+ // Grab the frame's pointer
+ int frame = GetObject(1);
+
+ // Get the object's point table
+ // local t_point = LUA_REGISTRYINDEX.OBJECT[frame].POINT
+ lua_getfield(L, LUA_REGISTRYINDEX, "OBJECT"); // +1 1
+ lua_pushvalue(L, frame); // +1 2
+ lua_gettable(L, -2); // +1 -1 2
+ lua_getfield(L, -1, "POINT"); // +1 3
+ int t_point = lua_gettop(L);
+
+ // Get the value of [0] on the stack
+ // return t_point[0]
+ lua_pushnumber(L, 0); // +1 4
+ lua_gettable(L, t_point); // +1 -1 4
+
+ return 1;
+}
+
+/// Lua function, edits the X and Y values of the specified point
+int L_EditPoint(lua_State *L)
+{
+ // Grab the frame's pointer
+ int frame = GetObject(1);
+
+ // Get the object's point table
+ // local t_point = LUA_REGISTRYINDEX.OBJECT[frame].POINT
+ lua_getfield(L, LUA_REGISTRYINDEX, "OBJECT"); // +1 1
+ lua_pushvalue(L, frame); // +1 2
+ lua_gettable(L, -2); // +1 -1 2
+ lua_getfield(L, -1, "POINT"); // +1 3
+ int t_point = lua_gettop(L);
+
+ // Get the table of the specified point
+ /// TODO: add checks to make sure the specified point exists, and is not index [0]
+ // t_point = t_point[point]
+ lua_pushvalue(L, 2); // +1 4
+ lua_gettable(L, t_point); // +1 -1 4
+ t_point = lua_gettop(L);
+
+ // Add in the new x and y values
+ // t_point.X = new_x
+ lua_pushvalue(L, 3); // +1 5
+ lua_setfield(L, t_point, "X"); // -1 4
+ // t_point.Y = new_y
+ lua_pushvalue(L, 4); // +1 5
+ lua_setfield(L, t_point, "Y"); // -1 4
+
+ return 0;
+}
+
+
+/// Lua function, sets the specified anchor point to the specified coordinates
+/// Parameters are: ("source", destobject, "dest", #off_1, #off_2)
+/// "source" is the point to anchor, "dest" is the point "source" will be anchored to,
+/// "destobject" is the object that point "dest" belongs to
+/// #off_1 is the first offset, #off_2 is the second offset, both or just one can be non-nil
+int L_SetAnchor(lua_State *L)
+{
+ // Grab the frame's pointer
+ int frame = GetObject(1);
+
+ // Grab the destination object's pointer
+ int dest = GetObject(3);
+
+ // Get the object's anchor table
+ // local t_anchor = LUA_REGISTRYINDEX.OBJECT[frame].ANCHOR
+ lua_getfield(L, LUA_REGISTRYINDEX, "OBJECT"); // +1 1
+ lua_pushvalue(L, frame); // +1 2
+ lua_gettable(L, -2); // +1 -1 2
+ lua_getfield(L, -1, "ANCHOR"); // +1 3
+ int t_anchor = lua_gettop(L);
+
+ // Check if the anchor list is already full
+ // if t_anchor.COMPLETED == true then return end
+ lua_getfield(L, t_anchor, "COMPLETED"); // +1 4
+ if (lua_toboolean(L, -1) == 1)
+ return 0;
+ lua_pop(L, 1); // -1 3
+
+ // Check if the anchor is self-referential
+ // if dest == frame then self_ref = true else self_ref = false end
+ bool self_ref;
+ if (lua_equal(L, frame, dest))
+ self_ref = true;
+ else
+ self_ref = false;
+
+ // Find which axes will be set
+ int x, y;
+ // if x_off == nil then
+ if (lua_isnil(L, 5))
+ x = 0;
+ else
+ x = 1;
+ // if y_off == nil then
+ if (lua_isnil(L, 6))
+ y = 0;
+ else
+ y = 1;
+ // Send an error if neither offset is defined
+ if (x == 0 and y == 0)
+ {
+ /// TODO: add an error here
+ return 0;
+ }
+
+ // Check if the right slots are available
+ // Move to the second slot if the anchor is self-referential
+ if (self_ref)
+ {
+ x *= 2;
+ y *= 2;
+ }
+ // Get the anchor slots
+ // t_x1 = t_anchor.X1
+ lua_getfield(L, t_anchor, "X1"); // +1 4
+ int t_x1 = lua_gettop(L);
+ // t_y1 = t_anchor.Y1
+ lua_getfield(L, t_anchor, "Y1"); // +1 5
+ int t_y1 = lua_gettop(L);
+ // t_x2 = t_anchor.X2
+ lua_getfield(L, t_anchor, "X2"); // +1 6
+ int t_x2 = lua_gettop(L);
+ // t_y2 = t_anchor.Y2
+ lua_getfield(L, t_anchor, "Y2"); // +1 7
+ int t_y2 = lua_gettop(L);
+ // Check if the desired slot is the first one
+ if (x == 1 or y == 1)
+ {
+ // If the first slot is taken, move to the second slot
+ // if x == 1 and t_x1 != nil then x = x*2 y = y*2
+ if (x == 1 && lua_isnil(L, t_x1) == 0)
+ {
+ x *= 2;
+ y *= 2;
+ }
+ // elseif y == 1 and t_y1 != nil then x = x*2 y = y*2 end
+ else if (y == 1 && lua_isnil(L, t_y1) == 0)
+ {
+ x *= 2;
+ y *= 2;
+ }
+ }
+ // Check if the desired slot is the second one
+ if (x == 2 or y == 2)
+ {
+ // If the second slot is taken, silently fail
+ // if x == 2 and t_x2 != nil then return
+ if (x == 2 && lua_isnil(L, t_x2) == 0)
+ return 0;
+ // elseif y == 2 and t_y2 != nil then return end
+ else if (y == 2 && lua_isnil(L, t_y2) == 0)
+ return 0;
+ }
+ // Set the coord anchor's values
+ // Make the new coord anchor
+ // local t_new = {}
+ lua_newtable(L);
+ int t_new = lua_gettop(L);
+ if (x == 1)
+ {
+ // t_new.SOURCE = source
+ lua_pushvalue(L, 2);
+ lua_setfield(L, t_new, "SOURCE");
+ // t_new.OFFSET = off_1
+ lua_pushvalue(L, 5);
+ lua_setfield(L, t_new, "OFFSET");
+ // t_new.DEST_OBJECT = destobject
+ lua_pushvalue(L, dest);
+ lua_setfield(L, t_new, "DEST_OBJECT");
+ // t_new.DEST_POINT = dest
+ lua_pushvalue(L, 4);
+ lua_setfield(L, t_new, "DEST_POINT");
+ // t_anchor.X1 = t_new
+ lua_setfield(L, t_anchor, "X1");
+ }
+ else if (x == 2)
+ {
+ // t_new.SOURCE = source
+ lua_pushvalue(L, 2);
+ lua_setfield(L, t_new, "SOURCE");
+ // t_new.OFFSET = off_1
+ lua_pushvalue(L, 5);
+ lua_setfield(L, t_new, "OFFSET");
+ // t_new.DEST_OBJECT = destobject
+ lua_pushvalue(L, dest);
+ lua_setfield(L, t_new, "DEST_OBJECT");
+ // t_new.DEST_POINT = dest
+ lua_pushvalue(L, 4);
+ lua_setfield(L, t_new, "DEST_POINT");
+ // t_anchor.X2 = t_new
+ lua_setfield(L, t_anchor, "X2");
+ }
+ // Make the new coord anchor
+ // local t_new = {}
+ lua_newtable(L);
+ t_new = lua_gettop(L);
+ if (y == 1)
+ {
+ // t_new.SOURCE = source
+ lua_pushvalue(L, 2);
+ lua_setfield(L, t_new, "SOURCE");
+ // if x == 0 then t_new.OFFSET = off_1 else t_new.OFFSET = off_2
+ if (x == 0)
+ lua_pushvalue(L, 5);
+ else
+ lua_pushvalue(L, 6);
+ lua_setfield(L, t_new, "OFFSET");
+ // t_new.DEST_OBJECT = destobject
+ lua_pushvalue(L, dest);
+ lua_setfield(L, t_new, "DEST_OBJECT");
+ // t_new.DEST_POINT = dest
+ lua_pushvalue(L, 4);
+ lua_setfield(L, t_new, "DEST_POINT");
+ // t_anchor.Y1 = t_new
+ lua_setfield(L, t_anchor, "Y1");
+ }
+ else if (y == 2)
+ {
+ // t_new.SOURCE = source
+ lua_pushvalue(L, 2);
+ lua_setfield(L, t_new, "SOURCE");
+ // if x == 0 then t_new.OFFSET = off_1 else t_new.OFFSET = off_2
+ if (x == 0)
+ lua_pushvalue(L, 5);
+ else
+ lua_pushvalue(L, 6);
+ lua_setfield(L, t_new, "OFFSET");
+ // t_new.DEST_OBJECT = destobject
+ lua_pushvalue(L, dest);
+ lua_setfield(L, t_new, "DEST_OBJECT");
+ // t_new.DEST_POINT = dest
+ lua_pushvalue(L, 4);
+ lua_setfield(L, t_new, "DEST_POINT");
+ // t_anchor.Y2 = t_new
+ lua_setfield(L, t_anchor, "Y2");
+ }
+
+ /// TODO: make it add the raw anchors, and make it check to prevent the same axis from being anchored multiple times
+ /// TODO: make it check and set [COMPLETED] if the anchors are now complete
+
+ return 0;
+}
+
+/// Lua function, returns the information on the specified anchor
+int L_GetAnchor(lua_State *L)
+{
+ /// TODO
+ return 6;
+}
+
+/// Lua function, returns the number of anchors that the region has set
+int L_GetAnchorCount(lua_State *L)
+{
+ // Grab the frame's pointer
+ int frame = GetObject(1);
+
+ // Get the object's anchor table
+ // local t_anchor = LUA_REGISTRYINDEX.OBJECT[frame].ANCHOR
+ lua_getfield(L, LUA_REGISTRYINDEX, "OBJECT"); // +1 1
+ lua_pushvalue(L, frame); // +1 2
+ lua_gettable(L, -2); // +1 -1 2
+ lua_getfield(L, -1, "ANCHOR"); // +1 3
+ int t_anchor = lua_gettop(L);
+
+ // Count how many raw anchors are set
+ lua_pushnil(L); // +1 4
+ int anchors;
+ for (anchors = 0; anchors < 4; anchors++)
+ {
+ // if t_anchor[anchors] == nil then break end
+ lua_pop(L, 1); // -1 3
+ lua_pushnumber(L, anchors); // +1 4
+ lua_gettable(L, t_anchor); // +1 -1 4
+ if (lua_isnil(L, -1) == 0)
+ break;
+ }
+
+ // return anchors
+ lua_pushnumber(L, anchors);
+ return 1;
+}
+
+/// Lua function, clears all of the region's anchors
+int L_ClearAnchors(lua_State *L)
+{
+ // Grab the frame's pointer
+ int frame = GetObject(1);
+
+ // Get the object's anchor table
+ // local t_anchor = LUA_REGISTRYINDEX.OBJECT[frame].ANCHOR
+ lua_getfield(L, LUA_REGISTRYINDEX, "OBJECT"); // +1 1
+ lua_pushvalue(L, frame); // +1 2
+ lua_gettable(L, -2); // +1 -1 2
+ lua_getfield(L, -1, "ANCHOR"); // +1 3
+ int t_anchor = lua_gettop(L);
+
+ // Clear the anchors
+ // t_anchor.X1 = nil
+ lua_pushnil(L); // +1 4
+ lua_setfield(L, t_anchor, "X1"); // -1 3
+ // t_anchor.X2 = nil
+ lua_pushnil(L); // +1 4
+ lua_setfield(L, t_anchor, "X2"); // -1 3
+ // t_anchor.Y1 = nil
+ lua_pushnil(L); // +1 4
+ lua_setfield(L, t_anchor, "Y1"); // -1 3
+ // t_anchor.Y2 = nil
+ lua_pushnil(L); // +1 4
+ lua_setfield(L, t_anchor, "Y2"); // -1 3
+ // t_anchor[1] = nil
+ lua_pushnumber(L, 1); // +1 4
+ lua_pushnil(L); // +1 5
+ lua_settable(L, t_anchor); // -2 3
+ // t_anchor[2] = nil
+ lua_pushnumber(L, 2); // +1 4
+ lua_pushnil(L); // +1 5
+ lua_settable(L, t_anchor); // -2 3
+ // t_anchor[3] = nil
+ lua_pushnumber(L, 3); // +1 4
+ lua_pushnil(L); // +1 5
+ lua_settable(L, t_anchor); // -2 3
+ // t_anchor[4] = nil
+ lua_pushnumber(L, 4); // +1 4
+ lua_pushnil(L); // +1 5
+ lua_settable(L, t_anchor); // -2 3
+
+ // Set COMPLETE and VALID to false
+ // t_anchor.COMPLETED = false
+ lua_pushboolean(L, false); // +1 4
+ lua_setfield(L, t_anchor, "COMPLETED"); // -1 3
+ // t_anchor.VALID = false
+ lua_pushboolean(L, false); // +1 4
+ lua_setfield(L, t_anchor, "VALID"); // -1 3
+
+ return 0;
+}*/
42 RougeMUD-Client/object_region.h
@@ -0,0 +1,42 @@
+#ifndef ROGUEMUD_OBJECT_REGION_H
+#define ROGUEMUD_OBJECT_REGION_H
+
+#include "object_frame.h"
+
+class Object_Region : public Object_Frame
+{
+ public:
+ Object_Region();
+ Object_Region(int new_table);
+ virtual ~Object_Region();
+ virtual void PopulateTable(lua_State *L, int new_table);
+ virtual void PopulateRegistry(lua_State *L);
+
+ int depth, x, y, width, height;
+ bool visible;
+ protected:
+ vector<Object_Region*> parentDB;
+ vector<Object_Region*> childDB;
+ private:
+};
+
+int L_Show(lua_State *L);
+int L_Hide(lua_State *L);
+int L_GetX(lua_State *L);
+int L_SetX(lua_State *L);
+int L_GetY(lua_State *L);
+int L_SetY(lua_State *L);
+int L_GetH(lua_State *L);
+int L_SetH(lua_State *L);
+int L_GetW(lua_State *L);
+int L_SetW(lua_State *L);
+/*int L_SetPoint(lua_State *L);
+int L_DelPoint(lua_State *L);
+int L_GetPoint(lua_State *L);
+int L_GetPointCount(lua_State *L);
+int L_SetAnchor(lua_State *L);
+int L_GetAnchor(lua_State *L);
+int L_GetAnchorCount(lua_State *L);
+int L_ClearAnchors(lua_State *L);*/
+
+#endif
25 RougeMUD-Client/object_secure.cpp
@@ -0,0 +1,25 @@
+#include "object_secure.h"
+
+Object_Secure::Object_Secure()
+{
+}
+
+Object_Secure::Object_Secure(int new_table)
+{
+ PopulateTable(LuaState, new_table);
+ PopulateRegistry(LuaState);
+}
+
+Object_Secure::~Object_Secure()
+{
+}
+
+void Object_Secure::PopulateTable(lua_State *L, int new_table)
+{
+ Object_Region::PopulateTable(LuaState, new_table);
+}
+
+void Object_Secure::PopulateRegistry(lua_State *L)
+{
+ Object_Region::PopulateRegistry(LuaState);
+}
18 RougeMUD-Client/object_secure.h
@@ -0,0 +1,18 @@
+#ifndef ROGUEMUD_OBJECT_SECURE_H
+#define ROGUEMUD_OBJECT_SECURE_H
+
+#include "object_region.h"
+
+class Object_Secure : public Object_Region
+{
+ public:
+ Object_Secure();
+ Object_Secure(int new_table);
+ virtual ~Object_Secure();
+ virtual void PopulateTable(lua_State *L, int new_table);
+ virtual void PopulateRegistry(lua_State *L);
+ protected:
+ private:
+};
+
+#endif
34 RougeMUD-Client/object_surface.cpp
@@ -0,0 +1,34 @@
+#include "object_surface.h"
+
+Object_Surface::Object_Surface()
+{
+ obj_surfaceDB[LAYER_NORMAL].push_back(this);
+}
+
+Object_Surface::Object_Surface(int new_table)
+{
+ // surface = imageDB[0];
+ obj_surfaceDB[LAYER_NORMAL].push_back(this);
+ PopulateTable(LuaState, new_table);
+ PopulateRegistry(LuaState);
+}
+
+Object_Surface::~Object_Surface()
+{
+ // SDL_FreeSurface(screen);
+}
+
+void Object_Surface::PopulateTable(lua_State *L, int new_table)
+{
+ Object_Region::PopulateTable(LuaState, new_table);
+}
+
+void Object_Surface::PopulateRegistry(lua_State *L)
+{
+ Object_Region::PopulateRegistry(LuaState);
+}
+
+void Object_Surface::Draw()
+{
+
+}
22 RougeMUD-Client/object_surface.h
@@ -0,0 +1,22 @@
+#ifndef ROGUEMUD_OBJECT_SURFACE_H
+#define ROGUEMUD_OBJECT_SURFACE_H
+
+#include "object_region.h"
+#include "ns_game.h"
+
+using namespace ns_game;
+
+class Object_Surface : public Object_Region
+{
+ public:
+ Object_Surface();
+ Object_Surface(int new_table);
+ virtual ~Object_Surface();
+ virtual void PopulateTable(lua_State *L, int new_table);
+ virtual void PopulateRegistry(lua_State *L);
+ virtual void Draw();
+ protected:
+ private:
+};
+
+#endif
30 RougeMUD-Client/object_text.cpp
@@ -0,0 +1,30 @@
+#include "object_text.h"
+
+Object_Text::Object_Text()
+{
+}
+
+Object_Text::Object_Text(int new_table)
+{
+ PopulateTable(LuaState, new_table);
+ PopulateRegistry(LuaState);
+}
+
+Object_Text::~Object_Text()
+{
+}
+
+void Object_Text::PopulateTable(lua_State *L, int new_table)
+{
+ Object_Surface::PopulateTable(LuaState, new_table);
+}
+
+void Object_Text::PopulateRegistry(lua_State *L)
+{
+ Object_Surface::PopulateRegistry(LuaState);
+}
+
+void Object_Text::Draw()