GODOT IS OPEN SOURCE

This commit is contained in:
Juan Linietsky
2014-02-09 22:10:30 -03:00
parent 0e49da1687
commit 0b806ee0fc
3138 changed files with 1294441 additions and 0 deletions

6
modules/gridmap/SCsub Normal file
View File

@@ -0,0 +1,6 @@
Import('env')
env.add_source_files(env.modules_sources,"*.cpp")

11
modules/gridmap/config.py Normal file
View File

@@ -0,0 +1,11 @@
def can_build(platform):
return True
def configure(env):
pass

1532
modules/gridmap/grid_map.cpp Normal file

File diff suppressed because it is too large Load Diff

271
modules/gridmap/grid_map.h Normal file
View File

@@ -0,0 +1,271 @@
/*************************************************************************/
/* grid_map.h */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#ifndef GRID_MAP_H
#define GRID_MAP_H
#include "scene/resources/mesh_library.h"
#include "scene/3d/spatial.h"
#include "scene/resources/multimesh.h"
//heh heh, godotsphir!! this shares no code and the design is completely different with previous projects i've done..
//should scale better with hardware that supports instancing
class GridMap : public Spatial {
OBJ_TYPE( GridMap, Spatial );
enum {
MAP_DIRTY_TRANSFORMS=1,
MAP_DIRTY_INSTANCES=2,
};
union IndexKey {
struct {
int16_t x;
int16_t y;
int16_t z;
};
uint64_t key;
_FORCE_INLINE_ bool operator<(const IndexKey& p_key) const {
return key < p_key.key;
}
IndexKey() { key=0; }
};
union Cell {
struct {
unsigned int item : 16;
unsigned int rot:5;
unsigned int layer:8;
};
uint32_t cell;
Cell() { item=0; rot=0; layer=0; }
};
struct Octant {
struct ItemInstances {
Set<IndexKey> cells;
Ref<Mesh> mesh;
Ref<Shape> shape;
Ref<MultiMesh> multimesh;
RID multimesh_instance;
};
Ref<Mesh> baked;
RID bake_instance;
bool dirty;
RID static_body;
Map<int,ItemInstances> items;
};
union OctantKey {
struct {
int16_t x;
int16_t y;
int16_t z;
int16_t area;
};
uint64_t key;
_FORCE_INLINE_ bool operator<(const OctantKey& p_key) const {
return key < p_key.key;
}
//OctantKey(const IndexKey& p_k, int p_item) { indexkey=p_k.key; item=p_item; }
OctantKey() { key=0; }
};
Transform last_transform;
bool _in_tree;
float cell_size;
int octant_size;
bool center_x,center_y,center_z;
bool bake;
float cell_scale;
bool clip;
bool clip_above;
int clip_floor;
bool baked_lock;
Vector3::Axis clip_axis;
struct Area {
String name;
RID base_portal;
RID instance;
IndexKey from;
IndexKey to;
struct Portal {
Transform xform;
RID instance;
~Portal();
};
Vector<Portal> portals;
float portal_disable_distance;
Color portal_disable_color;
bool exterior_portal;
Area();
~Area();
};
Ref<MeshLibrary> theme;
Map<OctantKey,Octant*> octant_map;
Map<IndexKey,Cell> cell_map;
Map<int,Area*> area_map;
void _recreate_octant_data();
struct BakeLight {
VS::LightType type;
Vector3 pos;
Vector3 dir;
float param[VS::LIGHT_PARAM_MAX];
};
_FORCE_INLINE_ int _find_area(const IndexKey& p_pos) const;
_FORCE_INLINE_ Vector3 _octant_get_offset(const OctantKey &p_key) const {
return Vector3(p_key.x,p_key.y,p_key.z)*cell_size*octant_size;
}
void _octant_enter_world(const OctantKey &p_key);
void _octant_exit_world(const OctantKey &p_key);
void _octant_update(const OctantKey &p_key);
void _octant_transform(const OctantKey &p_key);
void _octant_clear_baked(const OctantKey &p_key);
void _octant_bake(const OctantKey &p_key,const Ref<TriangleMesh>& p_tmesh=RES(),const Vector<BakeLight> &p_lights=Vector<BakeLight>(),List<Vector3> *r_prebake=NULL);
bool awaiting_update;
void _queue_dirty_map();
void _update_dirty_map_callback();
void resource_changed(const RES& p_res);
void _update_areas();
void _update_area_instances();
void _clear_internal(bool p_keep_areas=false);
protected:
bool _set(const StringName& p_name, const Variant& p_value);
bool _get(const StringName& p_name,Variant &r_ret) const;
void _get_property_list( List<PropertyInfo> *p_list) const;
void _notification(int p_what);
static void _bind_methods();
public:
enum {
INVALID_CELL_ITEM=-1
};
void set_theme(const Ref<MeshLibrary>& p_theme);
Ref<MeshLibrary> get_theme() const;
void set_cell_size(float p_size);
float get_cell_size() const;
void set_octant_size(int p_size);
int get_octant_size() const;
void set_center_x(bool p_enable);
bool get_center_x() const;
void set_center_y(bool p_enable);
bool get_center_y() const;
void set_center_z(bool p_enable);
bool get_center_z() const;
void set_cell_item(int p_x,int p_y,int p_z, int p_item,int p_orientation=0);
int get_cell_item(int p_x,int p_y,int p_z) const;
int get_cell_item_orientation(int p_x,int p_y,int p_z) const;
void set_clip(bool p_enabled, bool p_clip_above=true, int p_floor=0, Vector3::Axis p_axis=Vector3::AXIS_X);
Error create_area(int p_id,const AABB& p_area);
AABB area_get_bounds(int p_area) const;
void area_set_exterior_portal(int p_area,bool p_enable);
void area_set_name(int p_area,const String& p_name);
String area_get_name(int p_area) const;
bool area_is_exterior_portal(int p_area) const;
void area_set_portal_disable_distance(int p_area, float p_distance);
float area_get_portal_disable_distance(int p_area) const;
void area_set_portal_disable_color(int p_area, Color p_color);
Color area_get_portal_disable_color(int p_area) const;
void get_area_list(List<int> *p_areas) const;
void erase_area(int p_area);
int get_unused_area_id() const;
void set_cell_scale(float p_scale);
float get_cell_scale() const;
void set_bake(bool p_bake);
bool is_baking_enabled() const;
void bake_geometry();
void clear();
GridMap();
~GridMap();
};
#endif // CUBE_GRID_MAP_H

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,243 @@
/*************************************************************************/
/* grid_map_editor_plugin.h */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#ifndef GRID_MAP_EDITOR_PLUGIN_H
#define GRID_MAP_EDITOR_PLUGIN_H
#include "tools/editor/editor_plugin.h"
#include "tools/editor/editor_node.h"
#include "grid_map.h"
#include "tools/editor/pane_drag.h"
/**
@author Juan Linietsky <reduzio@gmail.com>
*/
class SpatialEditorPlugin;
class GridMapEditor : public VBoxContainer {
OBJ_TYPE(GridMapEditor, VBoxContainer );
enum {
GRID_CURSOR_SIZE=50
};
enum InputAction {
INPUT_NONE,
INPUT_PAINT,
INPUT_ERASE,
INPUT_COPY,
INPUT_SELECT,
INPUT_DUPLICATE,
};
enum ClipMode {
CLIP_DISABLED,
CLIP_ABOVE,
CLIP_BELOW
};
UndoRedo *undo_redo;
InputAction input_action;
Panel *panel;
MenuButton * options;
SpinBox *floor;
OptionButton *edit_mode;
HBoxContainer *spatial_editor_hb;
struct SetItem {
Vector3 pos;
int new_value;
int new_orientation;
int old_value;
int old_orientation;
};
List<SetItem> set_items;
GridMap *node;
MeshLibrary* last_theme;
ClipMode clip_mode;
bool lock_view;
Transform grid_xform;
Transform edit_grid_xform;
Vector3::Axis edit_axis;
int edit_floor[3];
Vector3 grid_ofs;
RID grid[3];
RID grid_instance[3];
RID cursor_instance;
RID selection_mesh;
RID selection_instance;
RID duplicate_mesh;
RID duplicate_instance;
bool updating;
struct Selection {
Vector3 click;
Vector3 current;
Vector3 begin;
Vector3 end;
int duplicate_rot;
bool active;
} selection;
bool cursor_visible;
Transform cursor_transform;
Vector3 cursor_origin;
Vector3 last_mouseover;
int selected_pallete;
int selected_area;
int cursor_rot;
enum Menu {
MENU_OPTION_CONFIGURE,
MENU_OPTION_NEXT_LEVEL,
MENU_OPTION_PREV_LEVEL,
MENU_OPTION_LOCK_VIEW,
MENU_OPTION_CLIP_DISABLED,
MENU_OPTION_CLIP_ABOVE,
MENU_OPTION_CLIP_BELOW,
MENU_OPTION_X_AXIS,
MENU_OPTION_Y_AXIS,
MENU_OPTION_Z_AXIS,
MENU_OPTION_CURSOR_ROTATE_Y,
MENU_OPTION_CURSOR_ROTATE_X,
MENU_OPTION_CURSOR_ROTATE_Z,
MENU_OPTION_CURSOR_BACK_ROTATE_Y,
MENU_OPTION_CURSOR_BACK_ROTATE_X,
MENU_OPTION_CURSOR_BACK_ROTATE_Z,
MENU_OPTION_CURSOR_CLEAR_ROTATION,
MENU_OPTION_DUPLICATE_SELECTS,
MENU_OPTION_SELECTION_MAKE_AREA,
MENU_OPTION_SELECTION_MAKE_EXTERIOR_CONNECTOR,
MENU_OPTION_SELECTION_CLEAR,
MENU_OPTION_REMOVE_AREA
};
SpatialEditorPlugin *spatial_editor;
struct AreaDisplay {
RID mesh;
RID instance;
};
Vector<AreaDisplay> areas;
void _update_areas_display();
void _clear_areas();
void update_grid();
void _configure();
void _menu_option(int);
void update_pallete();
Tree *theme_pallete;
Tree *area_list;
void _item_selected_cbk();
void _update_cursor_transform();
void _update_cursor_instance();
void _update_clip();
void _update_duplicate_indicator();
void _duplicate_paste();
void _update_selection_transform();
void _validate_selection();
void _edit_mode_changed(int p_what);
void _area_renamed();
void _area_selected();
void _floor_changed(float p_value);
void _delete_selection();
void update_areas();
EditorNode *editor;
bool do_input_action(Camera* p_camera,const Point2& p_point,bool p_click);
friend class GridMapEditorPlugin;
Panel *theme_panel;
protected:
void _notification(int p_what);
void _node_removed(Node *p_node);
static void _bind_methods();
public:
bool forward_spatial_input_event(Camera* p_camera,const InputEvent& p_event);
void edit(GridMap *p_gridmap);
GridMapEditor() {}
GridMapEditor(EditorNode *p_editor);
~GridMapEditor();
};
class GridMapEditorPlugin : public EditorPlugin {
OBJ_TYPE( GridMapEditorPlugin, EditorPlugin );
GridMapEditor *gridmap_editor;
EditorNode *editor;
public:
virtual bool forward_spatial_input_event(Camera* p_camera,const InputEvent& p_event) { return gridmap_editor->forward_spatial_input_event(p_camera,p_event); }
virtual String get_name() const { return "GridMap"; }
bool has_main_screen() const { return false; }
virtual void edit(Object *p_node);
virtual bool handles(Object *p_node) const;
virtual void make_visible(bool p_visible);
GridMapEditorPlugin(EditorNode *p_node);
~GridMapEditorPlugin();
};
#endif // CUBE_GRID_MAP_EDITOR_PLUGIN_H

View File

@@ -0,0 +1,47 @@
/*************************************************************************/
/* register_types.cpp */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "register_types.h"
#include "object_type_db.h"
#include "grid_map.h"
#include "grid_map_editor_plugin.h"
void register_gridmap_types() {
ObjectTypeDB::register_type<GridMap>();
#ifdef TOOLS_ENABLED
EditorPlugins::add_by_type<GridMapEditorPlugin>();
#endif
}
void unregister_gridmap_types() {
}

View File

@@ -0,0 +1,30 @@
/*************************************************************************/
/* register_types.h */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
void register_gridmap_types();
void unregister_gridmap_types();